Jump to content

Recommended Posts

Hi..

I need a random number each time I start up.

I gave a seed value initially on 'srand(int)' then called rand();

Though i gives a random number when I run the program, when I turn off and restart the program the same pattern random number is generated.

 

I need a different random number each time I start up. Thankyou

Share this post


Link to post
Share on other sites

Hi John,

 

If you have EEPROM you could save the initial random number and use that as the seed for the next power-up.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

thanks Rey,

But my problem is I have about 15 PICs with the same program. All powered up at the same time. But I need to start running the main() on each pic at slightly different time periods. I dont want all pic to run the main() at the same time as well as I cant write different code for each pic. Any help would be useful. Thank you.

 

Is there easy way to write to EEPROM while programming?

 

Jon

Share this post


Link to post
Share on other sites

Hi John,

 

If your PIC programmer is any good it will allow you to change/edit the EEPROM data before you program the device.

That way you can insert a unique serial number into each device and use that as your initial seed value etc.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

Hi John,

 

Also, if you have any external stimulus such as comms messages, button presses etc you could use them as trigger to sample bit 0 of a fast running timer and shift that into your seed.

 

Andy Leiper

IET Ltd

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...