Questions's in the title. time.cpuTime() wouldn't be helpful for seeding the RNG.
So what should be used?
This is what randomize() does:
randomize(cast[int](epochTime()))
Do you have any problem with using epochTime ?It depends. On a 32-bit machine, this will typically extract the first four bytes of the floating point number, which contain the sign bit, the exponent, and the most significant 20 bits of the mantissa. This loses information and may or may not be suitably random. Here's a function that tries to avoid this problem:
import times, math
proc getTimeSeed(): int =
let t = epochTime()
let th = int(t mod 1e9)
let tl = int((t mod 1) * 1e9)
when sizeof(int) == 4:
tl xor th
else:
th * 1_000_000_000 + tl
echo getTimeSeed()
echo getTimeSeed()