Random number generator

Status
Not open for further replies.

joe_1

Member
Hi:

I want to write PIC program which involves this situation: Generating random number from specific range of numbers.
For example if range is 300 - 900, then the random number generator will only pick up number from that range.
I saw in basic that there is function called RANDOM which generates number between 1-65k and does not restrict to a specified range.
If anyone has any hints, I'll appreciate it very much.
Thanx.
 

Generate a 16 bit random number (0-65535), divide it by 109 which scales it to (0-600), then add 300 to it. This will give your required 300-900 range.
 
joe_1 said:
Thankx.
I never thought it was that easy.

I know exactly what you mean!, sometimes you can over complicate things, then someone comes along with a nice simple method!.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…