Guest User

Untitled

a guest
Oct 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. use "random"
  2. use "time"
  3.  
  4. // How should one use the Random class?
  5. // if it is reading from a psudo file, then should we have one file descriptor
  6. // for that file?
  7. actor Main
  8.  
  9. new create(env: Env) =>
  10. env.out.print("Hello World")
  11.  
  12. // seed and prepare the PRNG once
  13. (let a: I64, let b: I64) = Time.now()
  14. let r: Random = Rand(a.u64(), b.u64())
  15. r.u128() // throw away the first bits - because the first bits seem to be predicable from XorOshiro128Plus
  16.  
  17. // pass it around for classes to claim random elements.
  18. let g: Genes val = Genes.create(8, r)
  19.  
  20. class val Genes
  21. let _genes: Array[U8] val
  22.  
  23. new val create(chromosones: USize, rand: Random) =>
  24. // rand: Random
  25. // this parameter must be sendable (iso, val or tag)
  26. let genes' = recover iso Array[U8](chromosones) end
  27. var i: USize = 0
  28. while i < chromosones do
  29. genes'.push(rand.u8())
  30. i = i + 1
  31. end
  32. _genes = recover val consume genes' end
Add Comment
Please, Sign In to add comment