fork download
  1. use std::time::SystemTime;
  2. use std::iter::once;
  3.  
  4. // Xorshiftで乱数を計算
  5. fn xorshift(seed: u64) -> u64 {
  6. [|x| x ^ (x << 13), |x| x ^ (x >> 7), |x| x ^ (x << 17)]
  7. .iter()
  8. .fold(seed, |acc, proc| proc(acc))
  9. }
  10.  
  11. // 現在時刻(UNIXタイム)を取得
  12. fn get_time_msec() -> u64 {
  13. let now = SystemTime::now();
  14. return match now.duration_since(SystemTime::UNIX_EPOCH) {
  15. Ok(t) => t.as_micros() as u64,
  16. Err(_) => 0,
  17. }
  18. }
  19.  
  20. fn main() {
  21. // 現在時刻でシードを初期化
  22. let seed = get_time_msec() ^ 123456789;
  23. // 300個の乱数を表示
  24. (0..300)
  25. .fold(vec![seed],
  26. |v, _|
  27. once(xorshift(v[0])).chain(v).collect::<Vec<u64>>())
  28. .into_iter()
  29. .rev()
  30. .map(|x| x % 6 + 1)
  31. .for_each(|x| print!("{}, ", x));
  32. println!("")
  33. }
  34.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
4, 6, 4, 3, 2, 6, 4, 5, 6, 5, 6, 3, 3, 6, 6, 4, 1, 4, 1, 1, 4, 2, 4, 1, 2, 3, 3, 4, 1, 1, 5, 4, 5, 3, 4, 6, 6, 4, 6, 3, 2, 6, 3, 3, 2, 3, 2, 5, 5, 5, 3, 1, 6, 6, 3, 2, 6, 6, 1, 6, 2, 4, 4, 3, 1, 5, 3, 3, 6, 4, 4, 6, 2, 2, 3, 5, 1, 6, 1, 6, 3, 6, 5, 4, 2, 2, 3, 4, 3, 3, 5, 2, 5, 5, 2, 4, 5, 1, 5, 6, 3, 1, 2, 5, 3, 2, 4, 3, 2, 2, 1, 1, 6, 3, 4, 3, 2, 2, 5, 3, 5, 6, 2, 5, 1, 4, 2, 4, 6, 4, 2, 2, 2, 6, 1, 3, 4, 5, 2, 4, 1, 1, 5, 2, 3, 5, 3, 5, 5, 2, 6, 5, 2, 4, 6, 5, 2, 6, 3, 1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