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 6971995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:54:39+00:00 2026-05-27T16:54:39+00:00

In regard to providing the long to seed java.util.Random , if I instantiate the

  • 0

In regard to providing the long to seed java.util.Random, if I instantiate the object once, it seems that if I just take the time as a seed that will be satisfactory for the life of the program, which for my purpose means that the result of a series of calls to nextDouble() looks random.

Suppose for reasons of code simplicity, I instantiate Random, use it several times, then re-instantiate, and repeat. If the seed is provided similarly, the seeds will be similar and increasing because it is based on the time. The increases will be small compared to the value if it is the number of seconds since January 1, 1970. (Edit: This question was asked in the year 2011.)

If I chain the output of nextDouble() does the re-instantiation of Random with a non-random time-based seed cause a subtle pattern to appear in the composite chain of output from nextDouble(). Another way to phrase this question is: do I need a seed drawn uniformly from the set of long.

  • 1 1 Answer
  • 0 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-27T16:54:40+00:00Added an answer on May 27, 2026 at 4:54 pm

    You probably are likely to run into a situation like this where indeed they will get assigned the same seed, particuarly if they’re created in the same millisecond. Some machines ahve a resolution as low as 15 milliseconds or more, so it becomes an even bigger problem.

    One way toget around this is to use Math.random(). It uses a system wide random instance that only ever gets instantiated the first time it’s used. I don’t believe you have access to the underlying instance, so you can’t use it to get nextInt() but you can use Math.random() for doubles, or if you really want your own Random object, get a double from Math.random(), convert its bits into a long and use that long as your seed for your new Random.

    Oracle docs for random can be found here.

    // create new random with seed from system random
    Random r = new Random(Double.doubleToLongBits(Math.random()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in regard to recursion what is a seed value?
My question is in regard to the way Java handles String literals. It's quite
Garbage Collection can become a time consuming process. In this regard, the GC tends
I've noticed with regard to the std::bad_cast exception that references and pointers don't seem
Of course you can regard it as a kind of strategy, but that applies
I have a set of text files providing informations that are parsed, analysed and
I've just finished reading 'Java for Dummies' and have begun to create a simple
I am finishing a Java library that I want to make available to third
This question is in regard to instances . That I asked earlier. Is it
My question is in regard to the SelectComman in the <asp:SqlDataSource ID=SqlDataSource2 runat=server ConnectionString=<%$

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.