Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Random number generation

Status
Not open for further replies.
Yes. A simple random function is:

Code:
#define M ((1<<14)-1)
#define C ((1<<12)-1)
uint16_t rnd()
{
    static uint16_t seed = 0;
    seed = ((uint32_t)M * seed + C) % (uint16_t)0xFFFE;
    return seed;
}
 
Last edited:
See Random number generation - Wikipedia, the free encyclopedia. The actual algorithm is shown in the Computational Methods section.

i.e. this one:
116-144550627858cb6d44ceb02ba9434317.png
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top