mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-31 20:00:09 +00:00
Update core:math/rand to use context.random_generator and remove rand.Rand
This commit is contained in:
@@ -54,8 +54,9 @@ test_xxhash_zero_streamed_random_updates :: proc(t: ^testing.T) {
|
||||
|
||||
// XXH3_128_update
|
||||
random_seed := rand.create(t.seed)
|
||||
context.random_generator = rand.default_random_generator(&random_seed)
|
||||
for len(b) > 0 {
|
||||
update_size := min(len(b), rand.int_max(8192, &random_seed))
|
||||
update_size := min(len(b), rand.int_max(8192))
|
||||
if update_size > 4096 {
|
||||
update_size %= 73
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ test_sort_with_indices :: proc(t: ^testing.T) {
|
||||
|
||||
for test_size in test_sizes {
|
||||
r := rand.create(t.seed)
|
||||
context.random_generator = rand.default_random_generator(&r)
|
||||
|
||||
vals := make([]u64, test_size)
|
||||
r_idx := make([]int, test_size) // Reverse index
|
||||
@@ -21,7 +22,7 @@ test_sort_with_indices :: proc(t: ^testing.T) {
|
||||
|
||||
// Set up test values
|
||||
for _, i in vals {
|
||||
vals[i] = rand.uint64(&r)
|
||||
vals[i] = rand.uint64()
|
||||
}
|
||||
|
||||
// Sort
|
||||
@@ -29,7 +30,7 @@ test_sort_with_indices :: proc(t: ^testing.T) {
|
||||
defer delete(f_idx)
|
||||
|
||||
// Verify sorted test values
|
||||
rand.init(&r, t.seed)
|
||||
rand.reset(t.seed)
|
||||
|
||||
for v, i in f_idx {
|
||||
r_idx[v] = i
|
||||
@@ -45,7 +46,7 @@ test_sort_with_indices :: proc(t: ^testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
idx_pass := vals[r_idx[i]] == rand.uint64(&r)
|
||||
idx_pass := vals[r_idx[i]] == rand.uint64()
|
||||
testing.expect(t, idx_pass, "Expected index to have been sorted")
|
||||
if !idx_pass {
|
||||
break
|
||||
@@ -62,6 +63,7 @@ test_sort_by_indices :: proc(t: ^testing.T) {
|
||||
|
||||
for test_size in test_sizes {
|
||||
r := rand.create(t.seed)
|
||||
context.random_generator = rand.default_random_generator(&r)
|
||||
|
||||
vals := make([]u64, test_size)
|
||||
r_idx := make([]int, test_size) // Reverse index
|
||||
@@ -72,7 +74,7 @@ test_sort_by_indices :: proc(t: ^testing.T) {
|
||||
|
||||
// Set up test values
|
||||
for _, i in vals {
|
||||
vals[i] = rand.uint64(&r)
|
||||
vals[i] = rand.uint64()
|
||||
}
|
||||
|
||||
// Sort
|
||||
@@ -80,7 +82,7 @@ test_sort_by_indices :: proc(t: ^testing.T) {
|
||||
defer delete(f_idx)
|
||||
|
||||
// Verify sorted test values
|
||||
rand.init(&r, t.seed)
|
||||
rand.reset(t.seed)
|
||||
|
||||
{
|
||||
indices := make([]int, test_size)
|
||||
|
||||
@@ -17,9 +17,10 @@ map_insert_random_key_value :: proc(t: ^testing.T) {
|
||||
|
||||
unique_keys := 0
|
||||
r := rand.create(t.seed + seed_incr)
|
||||
context.random_generator = rand.default_random_generator(&r)
|
||||
for _ in 0..<entries {
|
||||
k := rand.int63(&r)
|
||||
v := rand.int63(&r)
|
||||
k := rand.int63()
|
||||
v := rand.int63()
|
||||
|
||||
if k not_in m {
|
||||
unique_keys += 1
|
||||
@@ -37,11 +38,12 @@ map_insert_random_key_value :: proc(t: ^testing.T) {
|
||||
|
||||
// Reset randomizer and verify
|
||||
r = rand.create(t.seed + seed_incr)
|
||||
context.random_generator = rand.default_random_generator(&r)
|
||||
|
||||
num_fails := 0
|
||||
for _ in 0..<entries {
|
||||
k := rand.int63(&r)
|
||||
v := rand.int63(&r)
|
||||
k := rand.int63()
|
||||
v := rand.int63()
|
||||
|
||||
cond := m[k] == v
|
||||
if !cond {
|
||||
@@ -67,9 +69,11 @@ map_update_random_key_value :: proc(t: ^testing.T) {
|
||||
|
||||
unique_keys := 0
|
||||
r := rand.create(t.seed + seed_incr)
|
||||
context.random_generator = rand.default_random_generator(&r)
|
||||
|
||||
for _ in 0..<entries {
|
||||
k := rand.int63(&r)
|
||||
v := rand.int63(&r)
|
||||
k := rand.int63()
|
||||
v := rand.int63()
|
||||
|
||||
if k not_in m {
|
||||
unique_keys += 1
|
||||
@@ -89,20 +93,23 @@ map_update_random_key_value :: proc(t: ^testing.T) {
|
||||
|
||||
// Reset randomizer and update half the entries
|
||||
r = rand.create(t.seed + seed_incr)
|
||||
context.random_generator = rand.default_random_generator(&r)
|
||||
|
||||
for _ in 0..<half_entries {
|
||||
k := rand.int63(&r)
|
||||
v := rand.int63(&r)
|
||||
k := rand.int63()
|
||||
v := rand.int63()
|
||||
|
||||
m[k] = v + 42
|
||||
}
|
||||
|
||||
// Reset randomizer and verify
|
||||
r = rand.create(t.seed + seed_incr)
|
||||
context.random_generator = rand.default_random_generator(&r)
|
||||
|
||||
num_fails := 0
|
||||
for i in 0..<entries {
|
||||
k := rand.int63(&r)
|
||||
v := rand.int63(&r)
|
||||
k := rand.int63()
|
||||
v := rand.int63()
|
||||
|
||||
diff := i64(42) if i < half_entries else i64(0)
|
||||
cond := m[k] == (v + diff)
|
||||
@@ -129,9 +136,11 @@ map_delete_random_key_value :: proc(t: ^testing.T) {
|
||||
|
||||
unique_keys := 0
|
||||
r := rand.create(t.seed + seed_incr)
|
||||
context.random_generator = rand.default_random_generator(&r)
|
||||
|
||||
for _ in 0..<entries {
|
||||
k := rand.int63(&r)
|
||||
v := rand.int63(&r)
|
||||
k := rand.int63()
|
||||
v := rand.int63()
|
||||
|
||||
if k not_in m {
|
||||
unique_keys += 1
|
||||
@@ -151,20 +160,23 @@ map_delete_random_key_value :: proc(t: ^testing.T) {
|
||||
|
||||
// Reset randomizer and delete half the entries
|
||||
r = rand.create(t.seed + seed_incr)
|
||||
context.random_generator = rand.default_random_generator(&r)
|
||||
|
||||
for _ in 0..<half_entries {
|
||||
k := rand.int63(&r)
|
||||
_ = rand.int63(&r)
|
||||
k := rand.int63()
|
||||
_ = rand.int63()
|
||||
|
||||
delete_key(&m, k)
|
||||
}
|
||||
|
||||
// Reset randomizer and verify
|
||||
r = rand.create(t.seed + seed_incr)
|
||||
context.random_generator = rand.default_random_generator(&r)
|
||||
|
||||
num_fails := 0
|
||||
for i in 0..<entries {
|
||||
k := rand.int63(&r)
|
||||
v := rand.int63(&r)
|
||||
k := rand.int63()
|
||||
v := rand.int63()
|
||||
|
||||
if i < half_entries {
|
||||
if k in m {
|
||||
@@ -207,8 +219,10 @@ set_insert_random_key_value :: proc(t: ^testing.T) {
|
||||
|
||||
unique_keys := 0
|
||||
r := rand.create(t.seed + seed_incr)
|
||||
context.random_generator = rand.default_random_generator(&r)
|
||||
|
||||
for _ in 0..<entries {
|
||||
k := rand.int63(&r)
|
||||
k := rand.int63()
|
||||
if k not_in m {
|
||||
unique_keys += 1
|
||||
}
|
||||
@@ -225,10 +239,11 @@ set_insert_random_key_value :: proc(t: ^testing.T) {
|
||||
|
||||
// Reset randomizer and verify
|
||||
r = rand.create(t.seed + seed_incr)
|
||||
context.random_generator = rand.default_random_generator(&r)
|
||||
|
||||
num_fails := 0
|
||||
for _ in 0..<entries {
|
||||
k := rand.int63(&r)
|
||||
k := rand.int63()
|
||||
|
||||
cond := k in m
|
||||
if !cond {
|
||||
@@ -254,8 +269,10 @@ set_delete_random_key_value :: proc(t: ^testing.T) {
|
||||
|
||||
unique_keys := 0
|
||||
r := rand.create(t.seed + seed_incr)
|
||||
context.random_generator = rand.default_random_generator(&r)
|
||||
|
||||
for _ in 0..<entries {
|
||||
k := rand.int63(&r)
|
||||
k := rand.int63()
|
||||
|
||||
if k not_in m {
|
||||
unique_keys += 1
|
||||
@@ -275,17 +292,20 @@ set_delete_random_key_value :: proc(t: ^testing.T) {
|
||||
|
||||
// Reset randomizer and delete half the entries
|
||||
r = rand.create(t.seed + seed_incr)
|
||||
context.random_generator = rand.default_random_generator(&r)
|
||||
|
||||
for _ in 0..<half_entries {
|
||||
k := rand.int63(&r)
|
||||
k := rand.int63()
|
||||
delete_key(&m, k)
|
||||
}
|
||||
|
||||
// Reset randomizer and verify
|
||||
r = rand.create(t.seed + seed_incr)
|
||||
context.random_generator = rand.default_random_generator(&r)
|
||||
|
||||
num_fails := 0
|
||||
for i in 0..<entries {
|
||||
k := rand.int63(&r)
|
||||
k := rand.int63()
|
||||
|
||||
if i < half_entries {
|
||||
if k in m {
|
||||
|
||||
Reference in New Issue
Block a user