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 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.
 
joe_1 said:
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.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top