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

The Archive Base Latest Questions

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

Assuming that I am using the same seed by instantiating a static final Random

  • 0

Assuming that I am using the same seed by instantiating a static final Random object with new Random(), is it possible to get the same number twice by calling nextBytes in the same instance?

I am aware that for any given seed, all the possible “random” numbers can be determined, and it is really more like a sequence:

  synchronized protected int next(int bits) {
     seed = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1);
     return (int)(seed >>> (48 - bits));
}

So basically if I have this code:

private static final Random random = new Random();

 public void doSomething() {
   for (int i=0; i < 1000000000; i++) {
      byte byteArray[] = new byte[8];
      random.nextBytes(byteArray)
   }
 }

How likely is it that nextBytes will generate the same bytes before it goes thru all the possible numbers that it can generate?.

Would this return the same value before returning all the possible combinations for the given bits?. I am guessing yes, but how often would this happen?.

  • 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-23T10:02:23+00:00Added an answer on May 23, 2026 at 10:02 am

    Class Random uses a linear congruence generator with a very large period. It does not repeate an int value for a very long time. The call to nextBytes with an 8-byte array generates two int values and breaks each into four 8-bit values to fill the array.

    I believe it is impossible for consecutive calls to nextBytes to generate the same values. It would mean that the random number generator would have a period of 2. The docs specify a specific behavior for next that makes this impossible. (A subclass of Random, of course, can have any kind of pathological behavior you like, but an instance of java.util.Random will be well-behaved.)

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

Sidebar

Related Questions

Assuming the file exists (using os.path.exists(filename) to first make sure that it does), how
Assuming that best practices have been followed when designing a new database, how does
In JSF 1.1, I am assuming that GET requests are treated as initial requests
Assuming that writing nhibernate mapping files is not a big issue....or polluting your domain
Assuming that I want to use a hash as an ID instead of a
assuming that I know the PID of a process and want to do a
Assuming that I have a CronTriggerBean similar to <bean id=midMonthCronTrigger class=org.springframework.scheduling.quartz.CronTriggerBean> <property name=jobDetail ref=reminderJobDetail
Assuming that I have a typedef declared in my .h file as such: typedef
Assuming that I know there is a git-daemon running at git://git.mycompany.com , how can
Assuming that one event has multiple handlers, if any of event handlers throw an

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.