Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Generic User Avatar

C random integers on a raspberry pi, need seeding?


  • Please log in to reply
1 reply to this topic

#1 rp88

rp88

  •  Avatar image
  • Members
  • 3,846 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Local time:08:46 PM

Posted 09 March 2021 - 06:17 PM

I'm developing a C program to run on a raspberry pi and get launched as it powers on. I need to get random integers in various ranges and have been using Value=rand() % 100; . These are not for cryptographic purposes so pseudorandom is fine and "predictable" random is ok, but by random I do expect that the values given should be different between each time the program runs, occasionally repeating as you'd expect with randomness, but not always the same value. And yet I think I'm getting the same random value every time? The Pi is not on the internet so the clock only updates by as much time as the pi is powered on for.


Does this random source end some sort of seeding or what? Doesn't it like being called early after powerup?
Thanks

Edited by rp88, 09 March 2021 - 06:17 PM.

Back to visiting this site, every so often, been so busy in previous years.

BC AdBot (Login to Remove)

 


#2 Chris Cosgrove

Chris Cosgrove

  •  Avatar image
  • Site Admin
  • 32,124 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Scotland
  • Local time:08:46 PM

Posted 09 March 2021 - 06:54 PM

Long time since I used C, and I was never very good with it, but did you call the random function in your set up includes ?  Something like 'include rand (or random).h; ?

 

Chris Cosgrove






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users