Fix bootstrap
parent
8b5402afa3
commit
023a1defb5
|
@ -1,22 +1,12 @@
|
||||||
USING: kernel math sequences namespaces errors hashtables words
|
USING: kernel math sequences namespaces hashtables words
|
||||||
arrays parser compiler syntax io tools prettyprint optimizer
|
arrays parser compiler syntax io prettyprint optimizer
|
||||||
inference ;
|
random math.constants math.functions layouts random-tester.utils ;
|
||||||
IN: random-tester
|
IN: random-tester
|
||||||
|
|
||||||
! Tweak me
|
! Tweak me
|
||||||
: max-length 15 ; inline
|
: max-length 15 ; inline
|
||||||
: max-value 1000000000 ; inline
|
: max-value 1000000000 ; inline
|
||||||
|
|
||||||
: 10% ( -- bool ) 10 random 8 > ;
|
|
||||||
: 20% ( -- bool ) 10 random 7 > ;
|
|
||||||
: 30% ( -- bool ) 10 random 6 > ;
|
|
||||||
: 40% ( -- bool ) 10 random 5 > ;
|
|
||||||
: 50% ( -- bool ) 10 random 4 > ;
|
|
||||||
: 60% ( -- bool ) 10 random 3 > ;
|
|
||||||
: 70% ( -- bool ) 10 random 2 > ;
|
|
||||||
: 80% ( -- bool ) 10 random 1 > ;
|
|
||||||
: 90% ( -- bool ) 10 random 0 > ;
|
|
||||||
|
|
||||||
! varying bit-length random number
|
! varying bit-length random number
|
||||||
: random-bits ( n -- int )
|
: random-bits ( n -- int )
|
||||||
random 2 swap ^ random ;
|
random 2 swap ^ random ;
|
||||||
|
@ -31,32 +21,29 @@ IN: random-tester
|
||||||
SYMBOL: special-integers
|
SYMBOL: special-integers
|
||||||
[ { -1 0 1 } % most-negative-fixnum , most-positive-fixnum , first-bignum , ]
|
[ { -1 0 1 } % most-negative-fixnum , most-positive-fixnum , first-bignum , ]
|
||||||
{ } make \ special-integers set-global
|
{ } make \ special-integers set-global
|
||||||
: special-integers ( -- seq ) \ special-integers get ;
|
|
||||||
SYMBOL: special-floats
|
SYMBOL: special-floats
|
||||||
[ { 0.0 -0.0 } % e , pi , 1./0. , -1./0. , 0./0. , epsilon , epsilon neg , ]
|
[ { 0.0 -0.0 } % e , pi , 1./0. , -1./0. , 0./0. , epsilon , epsilon neg , ]
|
||||||
{ } make \ special-floats set-global
|
{ } make \ special-floats set-global
|
||||||
: special-floats ( -- seq ) \ special-floats get ;
|
|
||||||
SYMBOL: special-complexes
|
SYMBOL: special-complexes
|
||||||
[
|
[
|
||||||
{ -1 0 1 i -i } %
|
{ -1 0 1 C{ 0 1 } C{ 0 -1 } } %
|
||||||
e , e neg , pi , pi neg ,
|
e , e neg , pi , pi neg ,
|
||||||
0 pi rect> , 0 pi neg rect> , pi neg 0 rect> , pi pi rect> ,
|
0 pi rect> , 0 pi neg rect> , pi neg 0 rect> , pi pi rect> ,
|
||||||
pi pi neg rect> , pi neg pi rect> , pi neg pi neg rect> ,
|
pi pi neg rect> , pi neg pi rect> , pi neg pi neg rect> ,
|
||||||
e neg e neg rect> , e e rect> ,
|
e neg e neg rect> , e e rect> ,
|
||||||
] { } make \ special-complexes set-global
|
] { } make \ special-complexes set-global
|
||||||
: special-complexes ( -- seq ) \ special-complexes get ;
|
|
||||||
|
|
||||||
: random-fixnum ( -- fixnum )
|
: random-fixnum ( -- fixnum )
|
||||||
most-positive-fixnum random 1+ coin-flip [ neg 1- ] when >fixnum ;
|
most-positive-fixnum random 1+ 50% [ neg 1- ] when >fixnum ;
|
||||||
|
|
||||||
: random-bignum ( -- bignum )
|
: random-bignum ( -- bignum )
|
||||||
400 random-bits first-bignum + coin-flip [ neg ] when ;
|
400 random-bits first-bignum + 50% [ neg ] when ;
|
||||||
|
|
||||||
: random-integer ( -- n )
|
: random-integer ( -- n )
|
||||||
coin-flip [
|
50% [
|
||||||
random-fixnum
|
random-fixnum
|
||||||
] [
|
] [
|
||||||
coin-flip [ random-bignum ] [ special-integers random ] if
|
50% [ random-bignum ] [ special-integers get random ] if
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: random-positive-integer ( -- int )
|
: random-positive-integer ( -- int )
|
||||||
|
@ -67,12 +54,12 @@ SYMBOL: special-complexes
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: random-ratio ( -- ratio )
|
: random-ratio ( -- ratio )
|
||||||
1000000000 dup [ random ] 2apply 1+ / coin-flip [ neg ] when dup [ drop random-ratio ] unless 10% [ drop 0 ] when ;
|
1000000000 dup [ random ] 2apply 1+ / 50% [ neg ] when dup [ drop random-ratio ] unless 10% [ drop 0 ] when ;
|
||||||
|
|
||||||
: random-float ( -- float )
|
: random-float ( -- float )
|
||||||
coin-flip [ random-ratio ] [ special-floats random ] if
|
50% [ random-ratio ] [ special-floats get random ] if
|
||||||
coin-flip
|
50%
|
||||||
[ .0000000000000000001 /f ] [ coin-flip [ .00000000000000001 * ] when ] if
|
[ .0000000000000000001 /f ] [ 50% [ .00000000000000001 * ] when ] if
|
||||||
>float ;
|
>float ;
|
||||||
|
|
||||||
: random-number ( -- number )
|
: random-number ( -- number )
|
||||||
|
|
Loading…
Reference in New Issue