I need to make a biased random number generator for a video game. I want to have odd/prime numbers come up more frequently, and can work for a variable range of possible outputs, (You need to collect a prime number, and they don't occur frequently enough for the user to pass the level). Is there any simple way to implement this in a way that is roughly as fast the c standard library random number generator?
I would prefer to implement this C-Style (no class), and I would like to avoid the use of additional libraries.
Here are some solutions I thought of that won't work:
- Pregenerating a list of random numbers (Too memory inefficient, not dynamic enough for my needs)
- Performing a primality test on each number with a 50% chance of rejecting if it's not prime (Too CPU inefficent)
Aucun commentaire:
Enregistrer un commentaire