2020-09-18 18:18:03 +02:00
|
|
|
# Random Number Generator
|
|
|
|
|
|
|
|
I/O device type 10 is a random number generator. I do this as
|
|
|
|
part of the VM I/O extensions to allow implementors to use the
|
|
|
|
best approach on their host system.
|
2019-01-22 03:00:09 +01:00
|
|
|
|
2019-01-19 18:28:17 +01:00
|
|
|
~~~
|
|
|
|
{{
|
2019-10-14 17:17:43 +02:00
|
|
|
'io var
|
|
|
|
:identify
|
2020-11-19 20:33:47 +01:00
|
|
|
@io n:zero? 0; drop
|
2019-10-14 17:17:43 +02:00
|
|
|
#10 io:scan-for dup n:negative?
|
|
|
|
[ drop 'IO_DEVICE_TYPE_0010_NOT_FOUND s:put nl ]
|
2020-11-19 20:33:47 +01:00
|
|
|
[ !io ] choose ;
|
2020-09-18 18:18:03 +02:00
|
|
|
---reveal---
|
2019-10-14 22:33:58 +02:00
|
|
|
:io:rng-operation identify @io io:invoke ;
|
2019-01-19 18:28:17 +01:00
|
|
|
}}
|
2019-10-14 17:17:43 +02:00
|
|
|
|
2019-10-14 22:33:58 +02:00
|
|
|
:n:random (-n) io:rng-operation ;
|
2019-10-14 17:17:43 +02:00
|
|
|
~~~
|