Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6232037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:02:46+00:00 2026-05-24T10:02:46+00:00

Summary: I need a simple self-contained way to seed my RNG so that the

  • 0

Summary: I need a simple self-contained way to seed my RNG so that the seed is different every time the program is launched.

Details:

I often need to run the same program (which does calculations with random numbers, e.g. Monte Carlo simulation etc.) many times to have good statistics on the result. In this case it is important that the random number generator will have a different seed on each run.

I would like to have a simple, cross-platform solution for this that can be contained within the program itself. (I.e. I don’t want to always go to the trouble of having a script that launches each instance of the program with a different seed parameter.)

Note that using time(0) as a seed is not a good solution because the timer resolution is bad: if several processes are launched in parallel, they are likely to get the same seed from time(0).

Requirements:

  • as simple as possible
  • cross platform (currently I need it to work on Windows & Linux, x86 & x64 only).
  • self contained: shouldn’t rely on a special way of launching the program (passing the seed as a parameter from the launch script is too much trouble).
  • I’d like to wrap the whole thing into a small library that I can include in any new project with minimal effort and just do something like SeedMyRNG(getSeed());

EDIT:

Although my main question was about doing this in C (or C++), based on the pointers provided in the answer I found os.urandom() as a Python solution (which is also useful for me).

Related relevant question: How to use /dev/random or urandom in C?

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:02:46+00:00Added an answer on May 24, 2026 at 10:02 am

    “Cross-platform” is a subjective term. Do you mean “any platform” (you might encounter in the future) or “every platform” (on your list of supported platforms)? Here’s a pragmatic approach that I usually take:

    1. Check if you have /dev/urandom; if yes, seed from there.

    2. On Windows, use CryptGenRandom().

    3. If all else fails, seed from time().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the summary: I need to build a simple java web app that,
Executive summary: I need a way to determine whether a Windows process I've spawned
Summary I am after some advice on the easiest way to analyze simple data
Summary When I execute a very simple program using Perl's Benchmark utility. I get
I need to write a report that generates summary totals against a table with
(Summary: My users need to be able to edit the structure of their dynamically
Summary: 1. Need to open a new window to display a survey from a
Summary : is there a way to get the unique lines from a file
This should be simple, very simple, but I'm having a hard time with it.
I have a database that I need to connect to and select from. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.