Ensure that random-prime result has the right size

As noted by Slava, choosing the next prime following a random number
with a specified number of bits may give a number one more bit long.
db4
Samuel Tardieu 2009-08-29 21:42:15 +02:00
parent b7c50e6159
commit e5897d52b2
1 changed files with 2 additions and 1 deletions

View File

@ -56,7 +56,8 @@ PRIVATE>
: coprime? ( a b -- ? ) gcd nip 1 = ; foldable
: random-prime ( numbits -- p )
random-bits* next-prime ;
[ ] [ 2^ ] [ random-bits* next-prime ] tri
2dup < [ 2drop random-prime ] [ 2nip ] if ;
: estimated-primes ( m -- n )
dup log / ; foldable