This commit is contained in:
blueloveTH 2024-04-17 20:29:11 +08:00
parent 9d8207c6be
commit e940ac3068
2 changed files with 13 additions and 2 deletions

View File

@ -109,9 +109,9 @@ struct mt19937{
/* generates a random number on [a, b]-interval */
int64_t randint(int64_t a, int64_t b){
uint32_t delta = b - a + 1;
uint64_t delta = b - a + 1;
if(delta < 0x80000000UL){
return a + next_uint32() % delta;
return a + next_uint32() % (uint32_t)delta;
}else{
return a + next_uint64() % delta;
}

View File

@ -54,5 +54,16 @@ for i in range(len(seq)):
actual_w = res.count(seq[i]) / k
assert abs(actual_w - weights[i]) < max_error
# test seed
from random import randint, seed
seed(7)
a = randint(1, 100)
b = randint(-2**60, 1)
c = randint(50, 100)
assert (a, b, c) == (16, -418020281577586157, 76)
seed(7)
assert a == randint(1, 100)
assert b == randint(-2**60, 1)
assert c == randint(50, 100)