random is generic now -- iota random -> random
parent
7dc60e3625
commit
4c71d71907
|
@ -38,7 +38,7 @@ IN: bit-arrays.tests
|
|||
|
||||
[ t ] [
|
||||
100 [
|
||||
drop 100 [ 2 iota random zero? ] replicate
|
||||
drop 100 [ 2 random zero? ] replicate
|
||||
dup >bit-array >array =
|
||||
] all-integers?
|
||||
] unit-test
|
||||
|
|
|
@ -175,4 +175,4 @@ IN: calendar.tests
|
|||
[ t ] [ 1325376000 unix-time>timestamp 2012 <year-gmt> = ] unit-test
|
||||
[ t ] [ 1356998399 unix-time>timestamp 2013 <year-gmt> 1 seconds time- = ] unit-test
|
||||
|
||||
[ t ] [ 1500000000 iota random [ unix-time>timestamp timestamp>unix-time ] keep = ] unit-test
|
||||
[ t ] [ 1500000000 random [ unix-time>timestamp timestamp>unix-time ] keep = ] unit-test
|
||||
|
|
|
@ -4,5 +4,5 @@ USING: classes.struct.bit-accessors tools.test effects kernel
|
|||
sequences random stack-checker ;
|
||||
IN: classes.struct.bit-accessors.test
|
||||
|
||||
[ t ] [ 20 iota random 20 iota random bit-reader infer (( alien -- n )) effect= ] unit-test
|
||||
[ t ] [ 20 iota random 20 iota random bit-writer infer (( n alien -- )) effect= ] unit-test
|
||||
[ t ] [ 20 random 20 random bit-reader infer (( alien -- n )) effect= ] unit-test
|
||||
[ t ] [ 20 random 20 random bit-writer infer (( n alien -- )) effect= ] unit-test
|
||||
|
|
|
@ -337,7 +337,7 @@ ERROR: bug-in-fixnum* x y a b ;
|
|||
|
||||
[ ] [
|
||||
10000 [
|
||||
5 iota random iota [ drop 32 random-bits ] map product >bignum
|
||||
5 random iota [ drop 32 random-bits ] map product >bignum
|
||||
dup [ bignum>fixnum ] keep compiled-bignum>fixnum =
|
||||
[ drop ] [ "Oops" throw ] if
|
||||
] times
|
||||
|
|
|
@ -11,7 +11,7 @@ IN: concurrency.combinators.tests
|
|||
|
||||
[ { 1 4 9 } ] [ { 1 2 3 } [ sq ] parallel-map ] unit-test
|
||||
|
||||
[ { 1 4 9 } ] [ { 1 2 3 } [ 1000000 iota random sleep sq ] parallel-map ] unit-test
|
||||
[ { 1 4 9 } ] [ { 1 2 3 } [ 1000000 random sleep sq ] parallel-map ] unit-test
|
||||
|
||||
[ { 1 2 3 } [ dup 2 mod 0 = [ "Even" throw ] when ] parallel-map ]
|
||||
[ error>> "Even" = ] must-fail-with
|
||||
|
|
|
@ -57,7 +57,7 @@ test-2 "TEST2" {
|
|||
} define-persistent
|
||||
|
||||
: test-1-tuple ( -- tuple )
|
||||
f 100 iota random 100 iota random 100 iota random [ number>string ] tri@
|
||||
f 100 random 100 random 100 random [ number>string ] tri@
|
||||
test-1 boa ;
|
||||
|
||||
: db-tester ( test-db -- )
|
||||
|
|
|
@ -186,7 +186,7 @@ link-no-follow? off
|
|||
|
||||
: random-markup ( -- string )
|
||||
10 [
|
||||
2 iota random 1 = [
|
||||
2 random 1 = [
|
||||
{
|
||||
"[["
|
||||
"*"
|
||||
|
|
|
@ -26,11 +26,11 @@ SYMBOL: unique-retries
|
|||
<PRIVATE
|
||||
|
||||
: random-letter ( -- ch )
|
||||
26 iota random { CHAR: a CHAR: A } random + ;
|
||||
26 random { CHAR: a CHAR: A } random + ;
|
||||
|
||||
: random-ch ( -- ch )
|
||||
{ t f } random
|
||||
[ 10 iota random CHAR: 0 + ] [ random-letter ] if ;
|
||||
[ 10 random CHAR: 0 + ] [ random-letter ] if ;
|
||||
|
||||
: random-name ( -- string )
|
||||
unique-length get [ random-ch ] "" replicate-as ;
|
||||
|
|
|
@ -250,7 +250,7 @@ IN: math.intervals.tests
|
|||
dup full-interval eq? [
|
||||
drop 32 random-bits 31 2^ -
|
||||
] [
|
||||
[ ] [ from>> first ] [ to>> first ] tri over - iota random +
|
||||
[ ] [ from>> first ] [ to>> first ] tri over - random +
|
||||
2dup swap interval-contains? [
|
||||
nip
|
||||
] [
|
||||
|
@ -259,10 +259,10 @@ IN: math.intervals.tests
|
|||
] if ;
|
||||
|
||||
: random-interval ( -- interval )
|
||||
10 iota random 0 = [ full-interval ] [
|
||||
2000 iota random 1000 - dup 2 1000 iota random + +
|
||||
1 iota random zero? [ [ neg ] bi@ swap ] when
|
||||
4 iota random {
|
||||
10 random 0 = [ full-interval ] [
|
||||
2000 random 1000 - dup 2 1000 random + +
|
||||
1 random zero? [ [ neg ] bi@ swap ] when
|
||||
4 random {
|
||||
{ 0 [ [a,b] ] }
|
||||
{ 1 [ [a,b) ] }
|
||||
{ 2 [ (a,b) ] }
|
||||
|
@ -366,7 +366,7 @@ comparison-ops [
|
|||
|
||||
! Test that commutative interval ops really are
|
||||
: random-interval-or-empty ( -- obj )
|
||||
10 iota random 0 = [ empty-interval ] [ random-interval ] if ;
|
||||
10 random 0 = [ empty-interval ] [ random-interval ] if ;
|
||||
|
||||
: commutative-ops ( -- seq )
|
||||
{
|
||||
|
|
|
@ -78,7 +78,7 @@ PRIVATE>
|
|||
>odd (find-relative-prime) ;
|
||||
|
||||
: find-relative-prime ( n -- p )
|
||||
dup iota random find-relative-prime* ;
|
||||
dup random find-relative-prime* ;
|
||||
|
||||
ERROR: too-few-primes n numbits ;
|
||||
|
||||
|
|
|
@ -151,7 +151,7 @@ CONSTANT: vector-words
|
|||
|
||||
[ { } ] [
|
||||
with-ctors [
|
||||
[ 1000 iota random '[ _ ] ] dip '[ _ execute ]
|
||||
[ 1000 random '[ _ ] ] dip '[ _ execute ]
|
||||
] [ = ] check-optimizer
|
||||
] unit-test
|
||||
|
||||
|
@ -165,7 +165,7 @@ CONSTANT: vector-words
|
|||
|
||||
[ { } ] [
|
||||
boa-ctors [
|
||||
[ stack-effect in>> length [ 1000 iota random ] [ ] replicate-as ] keep
|
||||
[ stack-effect in>> length [ 1000 random ] [ ] replicate-as ] keep
|
||||
'[ _ execute ]
|
||||
] [ = ] check-optimizer
|
||||
] unit-test
|
||||
|
@ -175,12 +175,12 @@ CONSTANT: vector-words
|
|||
"== Checking vector operations" print
|
||||
|
||||
: random-int-vector ( class -- vec )
|
||||
new [ drop 1000 iota random ] map ;
|
||||
new [ drop 1000 random ] map ;
|
||||
|
||||
: random-float-vector ( class -- vec )
|
||||
new [
|
||||
drop
|
||||
1000 iota random
|
||||
1000 random
|
||||
10 swap <array> 0/0. suffix random
|
||||
] map ;
|
||||
|
||||
|
@ -193,7 +193,7 @@ CONSTANT: vector-words
|
|||
inputs [
|
||||
{
|
||||
{ +vector+ [ class elt-class random-vector ] }
|
||||
{ +scalar+ [ 1000 iota random elt-class float = [ >float ] when ] }
|
||||
{ +scalar+ [ 1000 random elt-class float = [ >float ] when ] }
|
||||
} case
|
||||
] [ ] map-as
|
||||
word '[ _ execute ] ;
|
||||
|
@ -255,13 +255,13 @@ simd-classes&reps [
|
|||
"== Checking boolean operations" print
|
||||
|
||||
: random-boolean-vector ( class -- vec )
|
||||
new [ drop 2 iota random zero? ] map ;
|
||||
new [ drop 2 random zero? ] map ;
|
||||
|
||||
:: check-boolean-op ( word inputs class elt-class -- inputs quot )
|
||||
inputs [
|
||||
{
|
||||
{ +vector+ [ class random-boolean-vector ] }
|
||||
{ +scalar+ [ 1000 iota random elt-class float = [ >float ] when ] }
|
||||
{ +scalar+ [ 1000 random elt-class float = [ >float ] when ] }
|
||||
} case
|
||||
] [ ] map-as
|
||||
word '[ _ execute ] ;
|
||||
|
@ -372,7 +372,7 @@ simd-classes&reps [
|
|||
[ [ 4 + ] map ] map
|
||||
[ append ] 2map
|
||||
] }
|
||||
[ dup '[ _ iota random ] replicate 1array ]
|
||||
[ dup '[ _ random ] replicate 1array ]
|
||||
} case ;
|
||||
|
||||
simd-classes [
|
||||
|
@ -387,7 +387,7 @@ simd-classes [
|
|||
"== Checking variable shuffles" print
|
||||
|
||||
: random-shift-vector ( class -- vec )
|
||||
new [ drop 16 iota random ] map ;
|
||||
new [ drop 16 random ] map ;
|
||||
|
||||
:: test-shift-vector ( class -- ? )
|
||||
[
|
||||
|
|
|
@ -81,7 +81,8 @@ M: hash-0-b hashcode* 2drop 0 ;
|
|||
] unit-test
|
||||
|
||||
: random-string ( -- str )
|
||||
1000000 iota random ; ! [ CHAR: a CHAR: z [a,b] random ] "" replicate-as ;
|
||||
1000000 random ;
|
||||
! [ CHAR: a CHAR: z [a,b] random ] "" replicate-as ;
|
||||
|
||||
: random-assocs ( n -- hash phash )
|
||||
[ random-string ] replicate
|
||||
|
|
|
@ -27,7 +27,7 @@ vectors math math.order ;
|
|||
[ t ] [
|
||||
3000 iota [
|
||||
drop
|
||||
16 random-bits 10000 iota random
|
||||
16 random-bits 10000 random
|
||||
[ "1" [ new-nth ] change ]
|
||||
[ "2" [ new-nth ] change ] 2bi
|
||||
"1" get "2" get sequence=
|
||||
|
@ -62,10 +62,10 @@ vectors math math.order ;
|
|||
[ t ] [
|
||||
100 iota [
|
||||
drop
|
||||
100 iota random [
|
||||
100 random [
|
||||
16 random-bits [ "1" [ ppush ] change ] [ "2" get push ] bi
|
||||
] times
|
||||
100 iota random "1" get length min [
|
||||
100 random "1" get length min [
|
||||
"1" [ ppop ] change
|
||||
"2" get pop*
|
||||
] times
|
||||
|
|
|
@ -3,12 +3,12 @@ random.mersenne-twister sequences tools.test math.order ;
|
|||
IN: random.mersenne-twister.tests
|
||||
|
||||
: check-random ( max -- ? )
|
||||
[ iota random 0 ] keep between? ;
|
||||
[ random 0 ] keep between? ;
|
||||
|
||||
[ t ] [ 100 [ drop 674 check-random ] all-integers? ] unit-test
|
||||
|
||||
: randoms ( -- seq )
|
||||
100 [ 100 iota random ] replicate ;
|
||||
100 [ 100 random ] replicate ;
|
||||
|
||||
: test-rng ( seed quot -- )
|
||||
[ <mersenne-twister> ] dip with-random ; inline
|
||||
|
|
|
@ -11,12 +11,12 @@ IN: random.tests
|
|||
[ 2 ] [ V{ 10 20 30 } [ delete-random drop ] keep length ] unit-test
|
||||
[ V{ } [ delete-random drop ] keep length ] must-fail
|
||||
|
||||
[ t ] [ 10000 [ iota 0 [ drop 187 iota random + ] reduce ] keep / 2 * 187 10 ~ ] unit-test
|
||||
[ t ] [ 10000 [ iota 0 [ drop 400 iota random + ] reduce ] keep / 2 * 400 10 ~ ] unit-test
|
||||
[ t ] [ 10000 [ iota 0 [ drop 187 random + ] reduce ] keep / 2 * 187 10 ~ ] unit-test
|
||||
[ t ] [ 10000 [ iota 0 [ drop 400 random + ] reduce ] keep / 2 * 400 10 ~ ] unit-test
|
||||
|
||||
[ t ] [ 1000 [ 400 iota random ] replicate prune length 256 > ] unit-test
|
||||
[ t ] [ 1000 [ 400 random ] replicate prune length 256 > ] unit-test
|
||||
|
||||
[ f ] [ 0 iota random ] unit-test
|
||||
[ f ] [ 0 random ] unit-test
|
||||
|
||||
[ { } ] [ { } randomize ] unit-test
|
||||
[ { 1 } ] [ { 1 } randomize ] unit-test
|
||||
|
|
|
@ -52,7 +52,7 @@ PRIVATE>
|
|||
|
||||
GENERIC: random ( obj -- elt )
|
||||
|
||||
M: integer random random-integer ;
|
||||
M: integer random [ f ] [ random-integer ] if-zero ;
|
||||
|
||||
M: sequence random
|
||||
[ f ] [
|
||||
|
@ -63,7 +63,7 @@ M: sequence random
|
|||
|
||||
: randomize ( seq -- seq )
|
||||
dup length [ dup 1 > ]
|
||||
[ [ iota random ] [ 1 - ] bi [ pick exchange ] keep ]
|
||||
[ [ random ] [ 1 - ] bi [ pick exchange ] keep ]
|
||||
while drop ;
|
||||
|
||||
ERROR: too-many-samples seq n ;
|
||||
|
|
|
@ -9,7 +9,7 @@ SPECIALIZED-ARRAY: double
|
|||
IN: serialize.tests
|
||||
|
||||
: test-serialize-cell ( a -- ? )
|
||||
2^ iota random dup
|
||||
2^ random dup
|
||||
binary [ serialize-cell ] with-byte-writer
|
||||
binary [ deserialize-cell ] with-byte-reader = ;
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ IN: unrolled-lists.tests
|
|||
|
||||
[ t ] [
|
||||
<unrolled-list>
|
||||
1000 [ 1000 iota random ] replicate
|
||||
1000 [ 1000 random ] replicate
|
||||
[ [ over push-front ] each ]
|
||||
[ length [ dup pop-back ] replicate ]
|
||||
[ ]
|
||||
|
@ -60,7 +60,7 @@ IN: unrolled-lists.tests
|
|||
|
||||
[ t ] [
|
||||
<unrolled-list>
|
||||
1000 [ 1000 iota random ] replicate
|
||||
1000 [ 1000 random ] replicate
|
||||
[
|
||||
10 group [
|
||||
[ [ over push-front ] each ]
|
||||
|
|
|
@ -216,8 +216,8 @@ unit-test
|
|||
|
||||
: random-integer ( -- n )
|
||||
32 random-bits
|
||||
1 iota random zero? [ neg ] when
|
||||
1 iota random zero? [ >bignum ] when ;
|
||||
1 random zero? [ neg ] when
|
||||
1 random zero? [ >bignum ] when ;
|
||||
|
||||
[ t ] [
|
||||
1000 [
|
||||
|
|
|
@ -11,7 +11,7 @@ unit-test
|
|||
[ t ] [
|
||||
100 [
|
||||
drop
|
||||
100 [ 20 iota random [ 1000 iota random ] replicate ] replicate
|
||||
100 [ 20 random [ 1000 random ] replicate ] replicate
|
||||
dup natural-sort
|
||||
[ set= ] [ nip [ before=? ] monotonic? ] 2bi and
|
||||
] all-integers?
|
||||
|
|
|
@ -26,7 +26,7 @@ IN: vectors.tests
|
|||
[ V{ 1 2 } ] [ [ 1 2 ] >vector ] unit-test
|
||||
|
||||
[ t ] [
|
||||
100 [ 100 iota random ] V{ } replicate-as
|
||||
100 [ 100 random ] V{ } replicate-as
|
||||
dup >array >vector =
|
||||
] unit-test
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ DEFER: check-status
|
|||
[ end-game ]
|
||||
[ dup quit? [ quit-game ] [ repeat ] if ]
|
||||
if ;
|
||||
: build-quad ( -- array ) 4 [ 10 iota random ] replicate ;
|
||||
: build-quad ( -- array ) 4 [ 10 random ] replicate ;
|
||||
: 24-able? ( quad -- t/f ) [ makes-24? ] with-datastack first ;
|
||||
: 24-able ( -- vector ) build-quad dup 24-able? [ drop build-quad ] unless ;
|
||||
: set-commands ( -- ) { + - * / rot swap q } commands set ;
|
||||
|
|
|
@ -7,7 +7,7 @@ IN: benchmark.random
|
|||
|
||||
: write-random-numbers ( n -- )
|
||||
random-numbers-path ascii [
|
||||
[ 200 iota random 100 - number>string print ] times
|
||||
[ 200 random 100 - number>string print ] times
|
||||
] with-file-writer ;
|
||||
|
||||
: random-main ( -- )
|
||||
|
|
|
@ -70,7 +70,7 @@ IN: bloom-filters.tests
|
|||
] unit-test
|
||||
|
||||
! We shouldn't have more than 0.01 false-positive rate.
|
||||
[ t ] [ 1000 iota [ drop most-positive-fixnum iota random 1000 + ] map
|
||||
[ t ] [ 1000 iota [ drop most-positive-fixnum random 1000 + ] map
|
||||
full-bloom-filter
|
||||
[ bloom-filter-member? ] curry map
|
||||
[ ] count
|
||||
|
|
|
@ -10,7 +10,7 @@ IN: decimals.tests
|
|||
] unit-test
|
||||
|
||||
: random-test-int ( -- n )
|
||||
10 iota random 2 iota random 0 = [ neg ] when ;
|
||||
10 random 2 random 0 = [ neg ] when ;
|
||||
|
||||
: random-test-decimal ( -- decimal )
|
||||
random-test-int random-test-int <decimal> ;
|
||||
|
|
|
@ -34,7 +34,7 @@ C: <oint> oint
|
|||
|
||||
: random-float+- ( n -- m )
|
||||
#! find a random float between -n/2 and n/2
|
||||
dup 10000 * >integer iota random 10000 / swap 2 / - ;
|
||||
dup 10000 * >integer random 10000 / swap 2 / - ;
|
||||
|
||||
: random-turn ( oint theta -- )
|
||||
2 / 2dup random-float+- left-pivot random-float+- up-pivot ;
|
||||
|
|
|
@ -21,7 +21,7 @@ C: <segment> segment
|
|||
0 swap length clamp ;
|
||||
|
||||
: random-color ( -- color )
|
||||
{ 100 100 100 } [ iota random 100 / >float ] map first3 1.0 <rgba> ;
|
||||
{ 100 100 100 } [ random 100 / >float ] map first3 1.0 <rgba> ;
|
||||
|
||||
CONSTANT: tunnel-segment-distance 0.4
|
||||
CONSTANT: random-rotation-angle $[ pi 20 / ]
|
||||
|
|
|
@ -5,7 +5,7 @@ sequences random sets make grouping ;
|
|||
IN: trees.splay.tests
|
||||
|
||||
: randomize-numeric-splay-tree ( splay-tree -- )
|
||||
100 iota [ drop 100 iota random swap at drop ] with each ;
|
||||
100 iota [ drop 100 random swap at drop ] with each ;
|
||||
|
||||
: make-numeric-splay-tree ( n -- splay-tree )
|
||||
iota <splay> [ [ conjoin ] curry each ] keep ;
|
||||
|
|
Loading…
Reference in New Issue