diff --git a/basis/random/random-tests.factor b/basis/random/random-tests.factor index 0fc4bb039e..89c0c02c4a 100644 --- a/basis/random/random-tests.factor +++ b/basis/random/random-tests.factor @@ -1,4 +1,5 @@ -USING: random sequences tools.test kernel math math.functions ; +USING: random sequences tools.test kernel math math.functions +sets ; IN: random.tests [ 4 ] [ 4 random-bytes length ] unit-test @@ -12,3 +13,5 @@ IN: random.tests [ t ] [ 10000 [ 0 [ drop 187 random + ] reduce ] keep / 2 * 187 10 ~ ] unit-test [ t ] [ 10000 [ 0 [ drop 400 random + ] reduce ] keep / 2 * 400 10 ~ ] unit-test + +[ t ] [ 1000 [ 400 random ] replicate prune length 256 > ] unit-test diff --git a/basis/random/random.factor b/basis/random/random.factor index c1dd146206..0a421288d5 100755 --- a/basis/random/random.factor +++ b/basis/random/random.factor @@ -36,10 +36,9 @@ M: f random-32* ( obj -- * ) no-random-number-generator ; : random ( seq -- elt ) [ f ] [ [ - length [ - log2 8 + 8 /i - random-bytes byte-array>bignum - ] keep mod + length dup log2 7 + 8 /i 1+ random-bytes + [ length 3 shift 2^ ] [ byte-array>bignum ] bi + swap / * >integer ] keep nth ] if-empty ;