Skip to content

Commit 37ca97d

Browse files
committed
Make site's shuffle call functional
1 parent d230b6c commit 37ca97d

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

site/src/main.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ use js_sys::Date;
1818
use leptos::*;
1919
use leptos_meta::*;
2020
use leptos_router::*;
21-
use rand::prelude::*;
21+
use rand_xoshiro::{
22+
rand_core::{RngCore, SeedableRng},
23+
Xoshiro256Plus,
24+
};
2225
use uiua::{now, ConstantDef, Primitive, SysOp};
2326
use uiua_editor::{
2427
binding_name_class, lang,
@@ -253,9 +256,23 @@ pub fn MainPage() -> impl IntoView {
253256
let indices = if visits < 4 {
254257
vec![0, rich_prims.len() - 3, rich_prims.len() - 1]
255258
} else {
256-
let mut rng = SmallRng::seed_from_u64(visits as u64);
257259
let mut indices: Vec<usize> = (0..rich_prims.len()).collect();
258-
indices.shuffle(&mut rng);
260+
{
261+
// Shuffle indices
262+
let l = indices.len();
263+
let upper = l.next_power_of_two();
264+
let mut rng = Xoshiro256Plus::seed_from_u64(visits as u64);
265+
266+
for i in 0..indices.len() {
267+
let index = loop {
268+
let r = rng.next_u64() as usize % upper;
269+
if r < l {
270+
break r;
271+
}
272+
};
273+
indices.swap(i, index);
274+
}
275+
}
259276
indices.truncate(3);
260277
indices.sort_unstable();
261278
indices

0 commit comments

Comments
 (0)