[LLVMdev] [LLVMDev] Does LLVM have a random number generator?
Jeff Kunkel
jdkunk3 at gmail.com
Sat Oct 9 05:01:28 PDT 2010
I am plugging this into my code. If someone wants to take it out and
add it to the llvm library, it's a simple Linear Congruential
Generator, but here it is:
typedef struct random_number_gen {
unsigned a, c, seed, m;
random_number_gen( unsigned seed, unsigned modulo ) :
seed(seed), m(modulo) {
unsigned primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 };
a = 1 + primes[ seed % ( sizeof(primes)/sizeof(primes[0]) ) ];
c = primes[ modulo % ( sizeof(primes)/sizeof(primes[0]) ) ];
}
unsigned rand() { return seed = (a*seed + c) % m; }
} random_number_gen;
-Thanks
-Jeff Kunkel
On Sat, Oct 9, 2010 at 1:10 AM, Jeff Kunkel <jdkunk3 at gmail.com> wrote:
> Hello, does LLVM already have a Random Number Generator built into
> it's library somewhere?
>
> I know code generation is suppose to be deterministic, but when
> producing a random number can be deterministic if the random number
> generator is also deterministic.
>
> - Thanks
> - Jeff Kunkel
>
More information about the llvm-dev
mailing list