Handbook
Glossary
weighted-randoms-as ( length histogram exemplar -- seq )
Vocabulary
math
.
extras
Inputs
length
an
object
histogram
an
object
exemplar
an
object
Outputs
seq
an
object
Definition
USING:
assocs
kernel
math
math.statistics
namespaces
random
sequences
sorting.extras
;
IN:
math.extras
:
weighted-randoms-as
( length histogram exemplar -- seq )
[
unzip
cum-sum
swap
[
[
last
>float
random-generator
get
]
keep
]
dip
[
[
[
random*
]
2curry
]
dip
[
bisect-left
]
curry
compose
]
dip
[
nth
]
curry
compose
]
dip
replicate-as
;
inline