22 lines
454 B
Text
22 lines
454 B
Text
fn random(mut random_source: File = File::open_for_reading("/dev/urandom")) throws -> u64 {
|
|
mut buffer = [0u8; 4]
|
|
random_source.read(buffer)
|
|
mut result = 0u64
|
|
for byte in buffer {
|
|
result <<= 8
|
|
result += byte as! u64
|
|
}
|
|
return result
|
|
}
|
|
|
|
fn main() {
|
|
while true {
|
|
let n = random() % 20
|
|
println("{}", n)
|
|
if n == 10 {
|
|
break
|
|
}
|
|
|
|
println("{}", random() % 20)
|
|
}
|
|
}
|