This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Random Numbers in a limited range

Hi all!!

I apologize my poor english.

I need to generate a serie of random numbers utilizing the functions RAND e SRAND in a limited range, ex 0 to 7, 30 to 76, etc.
How can I create these numbers??
Can anybody help me???

Thanks in advance.

Mauricio.

Parents
  • I seem to remember reading somewhere that the least significant bits of the return value of [a typical implementation of] rand() tend to be less 'random' than the most significant bits.

    I think that this applies to Linear Congruential Generators (LCG) that were, and still are, common. The Keil library function uses a Linear Feedback Shift Register (LFSR) method. In the case of an LFSR, all the bits are equally pseudo-random so that, aside from portablility issues, it really does not matter which bits you take.

Reply
  • I seem to remember reading somewhere that the least significant bits of the return value of [a typical implementation of] rand() tend to be less 'random' than the most significant bits.

    I think that this applies to Linear Congruential Generators (LCG) that were, and still are, common. The Keil library function uses a Linear Feedback Shift Register (LFSR) method. In the case of an LFSR, all the bits are equally pseudo-random so that, aside from portablility issues, it really does not matter which bits you take.

Children