The random module is not very good at all, sorry for that. But there is a mersenne twister in the standard library.
This is what I use. Upper bound is exclusive.
proc rand*(maxval: uint32): uint32 =
let limit = uint32(high(uint32)) - uint32(high(uint32)) mod maxval
var bits = rand_u32()
while bits > limit:
bits = rand_u32()
result = bits mod maxval
