Skip to content

Commit 0015f2b

Browse files
amatgilkaikalii
authored andcommitted
Make site's shuffle call functional
1 parent c18f4f7 commit 0015f2b

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
@@ -19,7 +19,10 @@ use js_sys::Date;
1919
use leptos::*;
2020
use leptos_meta::*;
2121
use leptos_router::*;
22-
use rand::prelude::*;
22+
use rand_xoshiro::{
23+
rand_core::{RngCore, SeedableRng},
24+
Xoshiro256Plus,
25+
};
2326
use uiua::{now, ConstantDef, Primitive, SysOp};
2427
use uiua_editor::{
2528
binding_name_class, lang,
@@ -261,9 +264,23 @@ pub fn MainPage() -> impl IntoView {
261264
let indices = if visits < 4 {
262265
vec![0, rich_prims.len() - 3, rich_prims.len() - 1]
263266
} else {
264-
let mut rng = SmallRng::seed_from_u64(visits as u64);
265267
let mut indices: Vec<usize> = (0..rich_prims.len()).collect();
266-
indices.shuffle(&mut rng);
268+
{
269+
// Shuffle indices
270+
let l = indices.len();
271+
let upper = l.next_power_of_two();
272+
let mut rng = Xoshiro256Plus::seed_from_u64(visits as u64);
273+
274+
for i in 0..indices.len() {
275+
let index = loop {
276+
let r = rng.next_u64() as usize % upper;
277+
if r < l {
278+
break r;
279+
}
280+
};
281+
indices.swap(i, index);
282+
}
283+
}
267284
indices.truncate(3);
268285
indices.sort_unstable();
269286
indices

0 commit comments

Comments
 (0)