Also, I am pretty sure that, besides being slow, `proc rand(r: var Rand; max: 
Natural)` is also buggy/biased. Git VC history says it used to be correct, but 
then someone hastily re-did some logic to make it range-inclusive. Briefly, 
    
    
    if x <= randMax - (randMax mod Ui(max)):
      return int(x mod (uint64(max) + 1u64))
    
    
    Run

should be 
    
    
    if x < randMax - (randMax mod (Ui(max) + Ui(1))):
      return int(x mod (Ui(max) + Ui(1)))
    
    
    Run

This does have follow-on impact for many derived algorithms, but it would be 
better still to just replace it with my faster version above, filled out for 
JavaScript BigInts & 32-bit fallbacks a la `hashes.nim:proc hash(int)`.

Reply via email to