Skip to content

Commit 9e1ea47

Browse files
authored
rand.mt19937: relax data for -autofree, update test (fix #13398) (#26266)
1 parent d6eb7a5 commit 9e1ea47

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

vlib/rand/mt19937/mt19937.v

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,13 @@ fn get_first_state(seed_data []u32) []u64 {
7373

7474
// calculate_state returns a random state array calculated from the `seed_data`.
7575
@[ignore_overflow]
76-
fn calculate_state(seed_data []u32, mut state []u64) []u64 {
76+
fn calculate_state(seed_data []u32, mut state []u64) {
7777
lo := u64(seed_data[0])
7878
hi := u64(seed_data[1])
7979
state[0] = u64((hi << 32) | lo)
8080
for j := 1; j < nn; j++ {
8181
state[j] = u64(6364136223846793005) * (state[j - 1] ^ (state[j - 1] >> 62)) + u64(j)
8282
}
83-
return *state
8483
}
8584

8685
// seed sets the current random state based on `seed_data`.
@@ -90,7 +89,7 @@ pub fn (mut rng MT19937RNG) seed(seed_data []u32) {
9089
eprintln('mt19937 needs only two 32bit integers as seed: [lower, higher]')
9190
exit(1)
9291
}
93-
rng.state = calculate_state(seed_data, mut rng.state)
92+
calculate_state(seed_data, mut rng.state)
9493
rng.mti = nn
9594
rng.bytes_left = 0
9695
rng.buffer = 0

vlib/rand/mt19937/mt19937_test.v

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ fn mt19937_basic_test() {
2424
fn gen_randoms(seed_data []u32, bound int) []u64 {
2525
bound_u64 := u64(bound)
2626
mut randoms := []u64{len: (20)}
27-
x := mt19937.MT19937RNG{}
28-
mut rnd := rand.PRNG(x)
27+
mut rnd := &rand.PRNG(&mt19937.MT19937RNG{})
2928
rnd.seed(seed_data)
3029
for i in 0 .. 20 {
3130
randoms[i] = rnd.u64n(bound_u64) or { panic("Couldn't obtain random u64") }

0 commit comments

Comments
 (0)