Post Reply 
(11C) Random Prime Number Generator
10-21-2018, 01:31 PM (This post was last modified: 10-21-2018 04:28 PM by Albert Chan.)
Post: #5
RE: (11C) Random Prime Number Generator
Hi, Gamo

Trivia: if I am betting for a number (< 10000) with this random prime generator, I'd pick 9587

Closest prime below 9587 is 9551, with a big gap of 36.
All 36 random integers (9552 to 9587) will go for 9587.

With prime table, removing prime gap bias is trivial: pick a random index, then lookup the prime.

(* Mathematica: primes below 10000 (1229 in total), all equally likely *)

Prime[Random[Integer, {1, 1229}]]

Update: without prime table, a simple way is keep picking random number until it is prime.
I think Klemm prime-wheel code do this ...
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(11C) Random Prime Number Generator - Gamo - 10-20-2018, 01:08 PM
RE: (11C) Random Prime Number Generator - Albert Chan - 10-21-2018 01:31 PM



User(s) browsing this thread: 1 Guest(s)