[ t ] [
100 [
- drop 100 [ 2 iota random zero? ] replicate
+ drop 100 [ 2 random zero? ] replicate
dup >bit-array >array =
] all-integers?
] unit-test
[ 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
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
[ ] [
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
\r
[ { 1 4 9 } ] [ { 1 2 3 } [ sq ] parallel-map ] unit-test\r
\r
-[ { 1 4 9 } ] [ { 1 2 3 } [ 1000000 iota random sleep sq ] parallel-map ] unit-test\r
+[ { 1 4 9 } ] [ { 1 2 3 } [ 1000000 random sleep sq ] parallel-map ] unit-test\r
\r
[ { 1 2 3 } [ dup 2 mod 0 = [ "Even" throw ] when ] parallel-map ]\r
[ error>> "Even" = ] must-fail-with\r
} 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 -- )
: random-markup ( -- string )
10 [
- 2 iota random 1 = [
+ 2 random 1 = [
{
"[["
"*"
<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 ;
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
] [
] 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) ] }
! 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 )
{
>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 ;
[ { } ] [
with-ctors [
- [ 1000 iota random '[ _ ] ] dip '[ _ execute ]
+ [ 1000 random '[ _ ] ] dip '[ _ execute ]
] [ = ] check-optimizer
] unit-test
[ { } ] [
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
"== 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 ;
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 ] ;
"== 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 ] ;
[ [ 4 + ] map ] map
[ append ] 2map
] }
- [ dup '[ _ iota random ] replicate 1array ]
+ [ dup '[ _ random ] replicate 1array ]
} case ;
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 -- ? )
[
] 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
[ 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=
[ 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
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
[ 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
GENERIC: random ( obj -- elt )
-M: integer random random-integer ;
+M: integer random [ f ] [ random-integer ] if-zero ;
M: sequence random
[ f ] [
: 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 ;
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 = ;
[ t ] [
<unrolled-list>
- 1000 [ 1000 iota random ] replicate
+ 1000 [ 1000 random ] replicate
[ [ over push-front ] each ]
[ length [ dup pop-back ] replicate ]
[ ]
[ t ] [
<unrolled-list>
- 1000 [ 1000 iota random ] replicate
+ 1000 [ 1000 random ] replicate
[
10 group [
[ [ over push-front ] each ]
: 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 [
[ 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?
[ 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
[ 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 ;
: 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 ( -- )
] 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
] 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> ;
: 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 ;
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 / ]
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 ;