1 USING: arrays help.markup help.syntax kernel math quotations
7 { "obj" "a random number generator" }
8 { "seed" "a seed specific to the random number generator" }
10 { $description "Seed the random number generator. Repeatedly seeding the random number generator should provide the same sequence of random numbers." }
11 { $notes "Not supported on all random number generators." } ;
14 { $values { "obj" "a random number generator" } { "n" "an integer between 0 and 2^32-1" } }
15 { $description "Generates a random 32-bit unsigned integer." } ;
18 { $values { "n" integer } { "obj" "a random number generator" } { "byte-array" "a sequence of random bytes" } }
19 { $description "Generates a byte-array of " { $snippet "n" } " random bytes." } ;
22 { $values { "obj" object } { "elt" "a random element" } }
23 { $description "Outputs a random element of the input object, or outputs " { $link f } " if the object contains no elements." }
25 { $unchecked-example "USING: random prettyprint ;"
28 { $unchecked-example "USING: random prettyprint ;"
31 "{ heads tails } random ."
36 { $values { "n" "a 32-bit random integer" } }
37 { $description "Outputs 32 random bits. This word is more efficient than calling " { $link random } " because no scaling is done on the output." } ;
40 { $values { "n" integer } { "byte-array" "a sequence of random bytes" } }
41 { $description "Generates a byte-array of " { $snippet "n" } " random bytes." }
43 { $unchecked-example "USING: prettyprint random ;"
45 "B{ 135 50 185 119 240 }"
50 { $values { "length" integer } { "n" integer } { "sequence" array } }
51 { $description "Outputs an array with " { $snippet "length" } " random integers from [0,n)." }
53 { $unchecked-example "USING: prettyprint random ;"
54 "10 100 random-integers ."
55 "{ 32 62 71 89 54 12 57 57 10 19 }"
60 { $values { "n" float } }
61 { $description "Outputs a random uniform float from [0,1]." } ;
64 { $values { "length" integer } { "sequence" array } }
65 { $description "Outputs an array with " { $snippet "length" } " random uniform floats from [0,1]." }
67 { $unchecked-example "USING: prettyprint random ;"
82 { $values { "numbits" integer } { "n" "a random integer" } }
83 { $description "Outputs a random integer " { $snippet "numbits" } " bits in length." } ;
86 { $values { "numbits" integer } { "n" "a random integer" } }
87 { $description "Returns an integer exactly " { $snippet "numbits" } " bits in length, with the topmost bit set to one." } ;
90 { $values { "obj" "a random number generator" } { "quot" quotation } }
91 { $description "Calls the quotation with the random number generator in a dynamic variable. All random numbers will be generated using this random number generator." } ;
93 HELP: with-secure-random
94 { $values { "quot" quotation } }
95 { $description "Calls the quotation with the secure random number generator in a dynamic variable. All random numbers will be generated using this random number generator." } ;
97 HELP: with-system-random
98 { $values { "quot" quotation } }
99 { $description "Calls the quotation with the system's random number generator in a dynamic variable. All random numbers will be generated using this random number generator." } ;
101 { with-random with-secure-random with-system-random } related-words
106 { "randomized" sequence }
108 { $description "Randomizes a sequence in-place with the Fisher-Yates algorithm and returns the sequence." } ;
112 { "seq" sequence } { "n" integer }
115 { $description "Takes " { $snippet "n" } " samples at random without replacement from a sequence. Throws an error if " { $snippet "n" } " is longer than the sequence." }
117 { $unchecked-example "USING: random prettyprint ;"
118 "{ 1 2 3 } 2 sample ."
127 { $description "Deletes a random number from a sequence using " { $link remove-nth! } " and returns the deleted object." } ;
129 ARTICLE: "random-protocol" "Random protocol"
130 "A random number generator must implement one of these two words:"
135 "Optional, to seed a random number generator:"
136 { $subsections seed-random } ;
138 ARTICLE: "random" "Generating random integers"
139 "The " { $vocab-link "random" } " vocabulary contains a protocol for generating random or pseudorandom numbers."
141 "The “Mersenne Twister” pseudorandom number generator algorithm is the default generator stored in " { $link random-generator } "."
143 "Generate a random object:"
144 { $subsections random }
145 "Efficient 32-bit random numbers:"
146 { $subsections random-32 }
147 "Combinators to change the random number generator:"
154 { $subsections "random-protocol" }
155 "Randomizing a sequence:"
156 { $subsections randomize }
157 "Sampling a sequences:"
158 { $subsections sample }
159 "Deleting a random element from a sequence:"
160 { $subsections delete-random }
161 "Sequences of random numbers:"
162 { $subsections random-bytes random-integers random-units }
163 "Random numbers with " { $snippet "n" } " bits:"