Hi, > The standard rand() function of many compilers (Keil, etc.) > return pseudorandom integer in range 0 to 32767. > 1. Is the period of such pseudorandom generators equal to > 2^15, or it is more? Good question. Usually these implementations are based on linear congruence, i.e next_random = (seed*x+y) modulo a smaller number. > 2. Who has an efficient algorithm for 2^31 period rand() > function? Both assembler and C realizations are of interest. Try Google, there are many PRANGs. It really depends upon your application what type of PRANG to employ e.g. uniform random numbers, Gaussian random numbers, and so on. Higher quality random numbers usually require more expensive computations and are, therefore, less efficient. As with implementation of transcendental and logarithmic approximations, there is more than one way to skin a cat, so just consider rand() a low-quality function that fulfils the requirements of the ISO standard. Boost has an appealing random number library: http://www.boost.org/libs/random/ -- Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk CrossWorks for MSP430, ARM, AVR and (soon) MAXQ processors
Message
RE: [lpc2000] rand() function
2005-05-03 by Paul Curtis
Attachments
- No local attachments were found for this message.