Fix deploy size regresson

db4
U-SLAVA-DFB8FF805\Slava 2008-10-05 22:08:13 -05:00
parent 66ae62638d
commit 0cfedcdc8d
2 changed files with 14 additions and 23 deletions

22
basis/random/random-docs.factor Normal file → Executable file
View File

@ -15,21 +15,18 @@ HELP: random-bytes*
{ $description "Generates a byte-array of random bytes." } ; { $description "Generates a byte-array of random bytes." } ;
HELP: random HELP: random
{ $values { "obj" object } { "elt" "a random element" } } { $values { "seq" sequence } { "elt" "a random element" } }
{ $description "Outputs a random element of the input object. If the object is an integer, an input of zero always returns a zero, while any other integer integers yield a random integer in the interval between itself and zero, inclusive of zero. On a sequence, an empty sequence always outputs " { $link f } "." } { $description "Outputs a random element of the input sequence. Outputs " { $link f } " if the sequence is empty." }
{ $notes "Since integers are sequences, passing an integer " { $snippet "n" } " outputs an integer in the interval " { $snippet "[0,n)" } "." }
{ $examples { $examples
{ $unchecked-example "USING: random prettyprint ;" { $unchecked-example "USING: random prettyprint ;"
"10 random ." "10 random ."
"3" } "3" }
{ $example "USING: random prettyprint ;"
"0 random ."
"0" }
{ $unchecked-example "USING: random prettyprint ;" { $unchecked-example "USING: random prettyprint ;"
"-10 random ." "SYMBOL: heads"
"-8" } "SYMBOL: tails"
{ $unchecked-example "USING: random prettyprint ;" "{ heads tails } random ."
"{ \"a\" \"b\" \"c\" } random ." "heads" }
"\"a\"" }
} ; } ;
HELP: random-bytes HELP: random-bytes
@ -74,7 +71,10 @@ ARTICLE: "random-protocol" "Random protocol"
{ $subsection seed-random } ; { $subsection seed-random } ;
ARTICLE: "random" "Generating random integers" ARTICLE: "random" "Generating random integers"
"The " { $vocab-link "random" } " vocabulary contains a protocol for generating random or pseudorandom numbers. The ``Mersenne Twister'' pseudorandom number generator algorithm is the default generator stored in " { $link random-generator } "." "The " { $vocab-link "random" } " vocabulary contains a protocol for generating random or pseudorandom numbers."
$nl
"The ``Mersenne Twister'' pseudorandom number generator algorithm is the default generator stored in " { $link random-generator } "."
$nl
"Generate a random object:" "Generate a random object:"
{ $subsection random } { $subsection random }
"Combinators to change the random number generator:" "Combinators to change the random number generator:"

15
basis/random/random.factor Normal file → Executable file
View File

@ -33,10 +33,6 @@ M: f random-32* ( obj -- * ) no-random-number-generator ;
random-generator get random-bytes* random-generator get random-bytes*
] keep head ; ] keep head ;
GENERIC: random ( obj -- elt )
: random-bits ( n -- r ) 2^ random ;
<PRIVATE <PRIVATE
: random-integer ( n -- n' ) : random-integer ( n -- n' )
@ -46,18 +42,13 @@ GENERIC: random ( obj -- elt )
PRIVATE> PRIVATE>
M: sequence random ( seq -- elt ) : random-bits ( n -- r ) 2^ random-integer ;
: random ( seq -- elt )
[ f ] [ [ f ] [
[ length random-integer ] keep nth [ length random-integer ] keep nth
] if-empty ; ] if-empty ;
M: integer random ( integer -- integer' )
dup sgn {
{ 0 [ ] }
{ -1 [ neg random-integer neg ] }
{ 1 [ random-integer ] }
} case ;
: delete-random ( seq -- elt ) : delete-random ( seq -- elt )
[ length random-integer ] keep [ nth ] 2keep delete-nth ; [ length random-integer ] keep [ nth ] 2keep delete-nth ;