Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Microchip PIC program problem

Status
Not open for further replies.
Code:
result = rand();      // generate random value from 0 to 32767
result = result/1000;

But the switch-case on your code considers only 10 options (0 to 9), which means that would be expected a lot of raffles without any update on the lottery display, something in the range of 1/3 ( ~10/32 )

Even though it's not the most uniform solution, The OP could have just done the following:
Code:
result = rand()%10; // generate a random value from 0 to 9

That is easier to understand and produces only numbers from 0-9 without having to deal with runs of results outside that range.
 
Even though it's not the most uniform solution, The OP could have just done the following:
Code:
result = rand()%10; // generate a random value from 0 to 9

That is easier to understand and produces only numbers from 0-9 without having to deal with runs of results outside that range.

Hi. thanks for your help. It works!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top