Handbook
Glossary
random-bytes* ( n rnd -- byte-array )
Generating random integers
ยป
Random protocol
Prev:
random-32* ( rnd -- n )
Next:
seed-random ( rnd seed -- rnd )
Vocabulary
random
Inputs
n
an
integer
rnd
a random number generator
Outputs
byte-array
a sequence of random bytes
Word description
Generates a byte-array of
n
random bytes.
See also
random-bytes
Definition
IN:
random
GENERIC:
random-bytes*
( n rnd -- byte-array )
Methods
USING:
alien.c-types
alien.data
byte-arrays
kernel
math
random
sequences
sequences.private
;
M:
base-random
random-bytes*
[
integer>fixnum-strict
[
(byte-array)
]
keep
]
dip
[
over
4
>=
]
[
[
4
-
]
dip
[
random-32*
2over
int
set-alien-value
]
keep
]
while
over
zero?
[
2drop
]
[
random-32*
int
<ref>
swap
head
0
pick
copy-unsafe
]
if
;
USING:
random
;
M:
f
random-bytes*
no-random-number-generator
;
USING:
kernel
random
;
M:
object
random-bytes*
not-a-random-generator
;
USING:
accessors
io
random
random.unix
;
M:
unix-random
random-bytes*
reader>>
stream-read
;