Guest User

Untitled

a guest
Mar 14th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. import math, random
  2. import ranks
  3.  
  4. const
  5. n = 100_000
  6. count = 100
  7. permCount = 120
  8.  
  9. template writeData(f: File; a: typed) =
  10. for i, v in a:
  11. f.writeLine(i, " ", v)
  12. f.write("\n\n")
  13.  
  14. proc testRandInt =
  15. let fs = open("randint.dat", fmWrite)
  16. # Get frequency of randoms
  17. var freqs: array[count, int]
  18. for i in 1 .. n:
  19. freqs[rand(count - 1)].inc
  20. fs.writeData(freqs)
  21. fs.close()
  22.  
  23. proc testRandFloat =
  24. let fs = open("randfloat.dat", fmWrite)
  25. var freqs: array[count, int]
  26. for i in 1 .. n:
  27. freqs[int(rand(1.0) * float(count))].inc
  28. fs.writeData(freqs)
  29. fs.close()
  30.  
  31. proc testShuffle =
  32. let fs = open("shuffle.dat", fmWrite)
  33. var freqs: array[permCount, int]
  34. for i in 1 .. n:
  35. var a = [0, 1, 2, 3, 4]
  36. shuffle(a)
  37. freqs[rank(a)].inc
  38. fs.writeData(freqs)
  39. fs.close()
  40.  
  41. testRandInt()
  42. testRandFloat()
  43. testShuffle()
Add Comment
Please, Sign In to add comment