mirror of
https://git.sr.ht/~crc_/retroforth
synced 2024-11-16 19:48:56 +01:00
e4eb91eb79
FossilOrigin-Name: 0787996383d82ab30c7b62dc4adf38c8360c6849f8e3b9d23f9e788d2d5322c7
20 lines
459 B
Text
20 lines
459 B
Text
# 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.
|
|
|
|
~~~
|
|
{{
|
|
'io var
|
|
:identify
|
|
@io n:zero? 0; drop
|
|
#10 io:scan-for dup n:negative?
|
|
[ drop 'IO_DEVICE_TYPE_0010_NOT_FOUND s:put nl ]
|
|
[ !io ] choose ;
|
|
---reveal---
|
|
:io:rng-operation identify @io io:invoke ;
|
|
}}
|
|
|
|
:n:random (-n) io:rng-operation ;
|
|
~~~
|