- Joined
- Sep 20, 2022
- Messages
- 269
- Reaction score
- 40
I recently had to do this to test some large numbers for primeness.
Let x be any 100 digit integer.
How would you select a random number, from 0 to x-1, with each possible value equally likely?
Let x be any 100 digit integer.
How would you select a random number, from 0 to x-1, with each possible value equally likely?
I can do exact integer arithmetic, but my floating point is limited to 14 significant figures.
Code:
string y = "1"
loop 200 times
append 1 random digit to y
end loop
y = x * y
truncate last 200 digits of y
return y - x