This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

A Fast way to get Random Numbers

Other Parts Discussed in Thread: SYSBIOS

Hi.

I'm looking for a way to generate random numbers which is simple and fast.

I'm using C6747 DSP, CCSv4 and SYSBIOS ver.6.

I once was suggested to use rand function in stdlib.h.

I haven't tested it yet, but I think there is a faster way.

Please let me know if someone knows a faster way than rand function in stdlib.h.

Thank you in advance.

Regards.

  • Hello,

    Here are two quick & dirty conguential pseudo-random generators that may help:

    x(n+1) = 65539 * x(n), with x(n) 32-bit unsigned odd numbers, period 2^30 (2 sub-series), seed x(0) must be odd

    x(n+1) = 0x41C64E6D * x(n) + 0x12345, with x(n) 32-bit unsigned numbers, period 2^32, unconstrained seed x(0)

  • Jakez

    Thank you for your advice.

    Is the second formula a type of Linear Congruential Generators?

    If you would not mind, please teach me the theoretical reason why this calculation generates random numbers.

    Regards.

  • Hello,

    Yes, it is a LCG.

    You can find all and more at http://en.wikipedia.org/wiki/Linear_congruential_generator (except the first generator x(n) = x(0) * 65539^n mod 2^32, fastest).

    The second generator mentioned is the Wikipedia glibc example : x(n+1) = x(n) * 1103515245 + 12345, but with a 0x12345 additive constant. The two constants generate maximal length sequences (2^32). Should have to determine which one gives the best randomness (if any), but... In Wikipedia we thrust.

    LCG are the simplest pseudo random generators, more randomness with a little more calculations can be obtained with lagged fibonacci generators.

    Regards