Handbook
Glossary
random* ( obj rnd -- elt )
Vocabulary
random
Inputs
obj
an
object
rnd
a random number generator
Outputs
elt
a random element
Word description
Outputs a random element of the input object, or outputs
f
if the object contains no elements.
See also
random
,
randoms
Definition
IN:
random
GENERIC#:
random*
1
( obj rnd -- elt )
Methods
USING:
assocs
kernel
random
;
M:
assoc
random*
[
>alist
]
dip
random*
;
USING:
math
random
random.private
;
M:
bignum
random*
random-integer
;
USING:
math
random
random.private
;
M:
fixnum
random*
random-integer
;
USING:
kernel
math
random
random.private
;
M:
float
random*
[
f
]
swap
[
[
0.0
]
]
dip
[
(uniform-random-float)
]
curry
compose
if-zero
;
inline
USING:
accessors
hash-sets
hashtables.private
kernel
math
random
sequences.private
sets
;
M:
hash-set
random*
[
dup
cardinality
[
drop
f
]
]
dip
[
random*
]
curry
[
[
[
0
]
[
array>>
]
]
]
dip
[
tri*
1
+
[
[
2dup
array-nth
tombstone?
[
1
+
]
2dip
]
loop
]
times
[
1
-
]
dip
array-nth
]
curry
compose
if-zero
;
USING:
accessors
arrays
assocs
hashtables
hashtables.private
kernel
math
random
sequences.private
;
M:
hashtable
random*
[
dup
assoc-size
[
drop
f
]
]
dip
[
random*
]
curry
[
[
[
0
]
[
array>>
]
]
]
dip
[
tri*
1
+
[
[
2dup
array-nth
tombstone?
[
2
+
]
2dip
]
loop
]
times
[
2
-
]
dip
[
array-nth
]
[
[
1
+
]
dip
array-nth
]
2bi
2array
]
curry
compose
if-zero
;
USING:
kernel
random
sequences
;
M:
sequence
random*
[
f
]
swap
[
[
length
]
]
dip
[
random*
]
curry
compose
[
keep
nth
]
curry
if-empty
;
USING:
kernel
random
sets
;
M:
set
random*
[
members
]
dip
random*
;
USING:
accessors
kernel
kernel.private
math
math.extras
random
random.private
sequences.private
;
M::
vose
random*
( obj rnd -- elt )
obj
n>>
rnd
random*
{
fixnum
}
declare
dup
obj
probs>>
nth-unsafe
{
float
}
declare
rnd
(random-unit)
>=
[
obj
alias>>
nth-unsafe
{
fixnum
}
declare
]
unless
obj
items>>
nth-unsafe
;