no uniqueCounter it is
This commit is contained in:
parent
33cabeb04d
commit
e9bbc7235d
2 changed files with 7 additions and 9 deletions
|
|
@ -188,11 +188,10 @@ when not defined(ECMAScript):
|
||||||
proc rand(): cint {.importc: "rand", nodecl.}
|
proc rand(): cint {.importc: "rand", nodecl.}
|
||||||
proc drand48(): float {.importc: "drand48", nodecl.}
|
proc drand48(): float {.importc: "drand48", nodecl.}
|
||||||
|
|
||||||
var uniqueCounter: int = 0
|
|
||||||
proc randomize() =
|
proc randomize() =
|
||||||
srand(gettime(nil) + cint(uniqueCounter))
|
let x = gettime(nil)
|
||||||
srand48(gettime(nil) + cint(uniqueCounter))
|
srand(x)
|
||||||
atomicInc(uniqueCounter)
|
srand48(x)
|
||||||
proc random(max: int): int =
|
proc random(max: int): int =
|
||||||
result = int(rand()) mod max
|
result = int(rand()) mod max
|
||||||
proc random(max: float): float =
|
proc random(max: float): float =
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,10 @@ import sets
|
||||||
suite "random int":
|
suite "random int":
|
||||||
test "there might be some randomness":
|
test "there might be some randomness":
|
||||||
var set = initSet[int](128)
|
var set = initSet[int](128)
|
||||||
for i in 1..10:
|
randomize()
|
||||||
for j in 1..10:
|
for i in 1..1000:
|
||||||
randomize()
|
incl(set, random(high(int)))
|
||||||
incl(set, random(high(int)))
|
check len(set) == 1000
|
||||||
check len(set) == 100
|
|
||||||
test "single number bounds work":
|
test "single number bounds work":
|
||||||
randomize()
|
randomize()
|
||||||
var rand: int
|
var rand: int
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue