Clean up random and fix circular
parent
0d9947198c
commit
e9d7e2523c
|
@ -57,7 +57,7 @@ millis >r
|
||||||
|
|
||||||
default-image-name "output-image" set-global
|
default-image-name "output-image" set-global
|
||||||
|
|
||||||
"math help handbook compiler tools ui ui.tools io" "include" set-global
|
"math help handbook compiler random tools ui ui.tools io" "include" set-global
|
||||||
"" "exclude" set-global
|
"" "exclude" set-global
|
||||||
|
|
||||||
parse-command-line
|
parse-command-line
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
USING: vocabs.loader sequences system
|
USING: vocabs.loader sequences system
|
||||||
random random.mersenne-twister ;
|
random random.mersenne-twister combinators init
|
||||||
|
namespaces ;
|
||||||
|
|
||||||
"random.mersenne-twister" require
|
"random.mersenne-twister" require
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ circular strings ;
|
||||||
[ CHAR: t ] [ "test" <circular> 0 swap nth ] unit-test
|
[ CHAR: t ] [ "test" <circular> 0 swap nth ] unit-test
|
||||||
[ "test" ] [ "test" <circular> >string ] unit-test
|
[ "test" ] [ "test" <circular> >string ] unit-test
|
||||||
|
|
||||||
[ "test" <circular> 5 swap nth ] must-fail
|
|
||||||
[ CHAR: e ] [ "test" <circular> 5 swap nth-unsafe ] unit-test
|
[ CHAR: e ] [ "test" <circular> 5 swap nth-unsafe ] unit-test
|
||||||
|
|
||||||
[ [ 1 2 3 ] ] [ { 1 2 3 } <circular> [ ] like ] unit-test
|
[ [ 1 2 3 ] ] [ { 1 2 3 } <circular> [ ] like ] unit-test
|
||||||
|
@ -18,10 +17,13 @@ circular strings ;
|
||||||
[ [ 3 1 2 ] ] [ { 1 2 3 } <circular> -100 over change-circular-start [ ] like ] unit-test
|
[ [ 3 1 2 ] ] [ { 1 2 3 } <circular> -100 over change-circular-start [ ] like ] unit-test
|
||||||
|
|
||||||
[ "fob" ] [ "foo" <circular> CHAR: b 2 pick set-nth >string ] unit-test
|
[ "fob" ] [ "foo" <circular> CHAR: b 2 pick set-nth >string ] unit-test
|
||||||
[ "foo" <circular> CHAR: b 3 rot set-nth ] must-fail
|
|
||||||
[ "boo" ] [ "foo" <circular> CHAR: b 3 pick set-nth-unsafe >string ] unit-test
|
[ "boo" ] [ "foo" <circular> CHAR: b 3 pick set-nth-unsafe >string ] unit-test
|
||||||
[ "ornact" ] [ "factor" <circular> 4 over change-circular-start CHAR: n 2 pick set-nth >string ] unit-test
|
[ "ornact" ] [ "factor" <circular> 4 over change-circular-start CHAR: n 2 pick set-nth >string ] unit-test
|
||||||
|
|
||||||
[ "bcd" ] [ 3 <circular-string> "abcd" [ over push-circular ] each >string ] unit-test
|
[ "bcd" ] [ 3 <circular-string> "abcd" [ over push-circular ] each >string ] unit-test
|
||||||
|
|
||||||
[ { 0 0 } ] [ { 0 0 } <circular> -1 over change-circular-start >array ] unit-test
|
[ { 0 0 } ] [ { 0 0 } <circular> -1 over change-circular-start >array ] unit-test
|
||||||
|
|
||||||
|
! This no longer fails
|
||||||
|
! [ "test" <circular> 5 swap nth ] must-fail
|
||||||
|
! [ "foo" <circular> CHAR: b 3 rot set-nth ] must-fail
|
||||||
|
|
|
@ -18,9 +18,9 @@ M: circular length circular-seq length ;
|
||||||
|
|
||||||
M: circular virtual@ circular-wrap circular-seq ;
|
M: circular virtual@ circular-wrap circular-seq ;
|
||||||
|
|
||||||
M: circular nth bounds-check virtual@ nth ;
|
M: circular nth virtual@ nth ;
|
||||||
|
|
||||||
M: circular set-nth bounds-check virtual@ set-nth ;
|
M: circular set-nth virtual@ set-nth ;
|
||||||
|
|
||||||
: change-circular-start ( n circular -- )
|
: change-circular-start ( n circular -- )
|
||||||
#! change start to (start + n) mod length
|
#! change start to (start + n) mod length
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
USING: kernel math random namespaces random.mersenne-twister
|
USING: kernel math random namespaces random.mersenne-twister
|
||||||
sequences tools.test ;
|
sequences tools.test ;
|
||||||
IN: random.mersenne-twister.tests
|
IN: random.mersenne-twister.tests
|
||||||
USE: tools.walker
|
|
||||||
|
|
||||||
: check-random ( max -- ? )
|
: check-random ( max -- ? )
|
||||||
dup >r random 0 r> between? ;
|
dup >r random 0 r> between? ;
|
||||||
|
@ -17,11 +16,11 @@ USE: tools.walker
|
||||||
[ f ] [ 1234 [ make-100-randoms make-100-randoms = ] test-rng ] unit-test
|
[ f ] [ 1234 [ make-100-randoms make-100-randoms = ] test-rng ] unit-test
|
||||||
|
|
||||||
[ 1333075495 ] [
|
[ 1333075495 ] [
|
||||||
0 [ 1000 [ drop \ random get random-32 drop ] each \ random get random-32 ] test-rng
|
0 [ 1000 [ drop random-generator get random-32 drop ] each random-generator get random-32 ] test-rng
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ 1575309035 ] [
|
[ 1575309035 ] [
|
||||||
0 [ 10000 [ drop \ random get random-32 drop ] each \ random get random-32 ] test-rng
|
0 [ 10000 [ drop random-generator get random-32 drop ] each random-generator get random-32 ] test-rng
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,8 @@
|
||||||
! mersenne twister based on
|
! mersenne twister based on
|
||||||
! http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c
|
! http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c
|
||||||
|
|
||||||
USING: arrays kernel math namespaces sequences
|
USING: arrays kernel math namespaces sequences system init
|
||||||
system init new-slots accessors
|
new-slots accessors math.ranges combinators.cleave random ;
|
||||||
math.ranges combinators.cleave circular random ;
|
|
||||||
IN: random.mersenne-twister
|
IN: random.mersenne-twister
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
Loading…
Reference in New Issue