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

The Archive Base Latest Questions

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

While making a map generator in Java I found a rather unnerving problem with

  • 0

While making a map generator in Java I found a rather unnerving problem with their random number generator, to specify, when two RNGs have very similar seeds (differing in small integers) their first output value will become very similar!

Example code:

Random r = new Random();
long n = 100000; //Choose any number
r.setSeed(n);  
System.out.println(r.nextInt());
r.setSeed(n+1);
System.out.println(r.nextInt());

This pretty much broke my faith in the original Java RNG, since I use coordinates to seed a map generator.
Could someone suggest either a redefinition for the Random.next(int bits) method, or some other fix for this problem?

Thank you for your help!

  • 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-22T16:39:59+00:00Added an answer on May 22, 2026 at 4:39 pm

    did you compare the sequence of the first ~20 values you get from 100000 and 100001?

    these are the first 20 nextInts of seeds 100000 and 100001 resp. with in the third column the amount of different bits (bitcount of the xor between the 2)

    this last column should remain around 16

    -1986972922 -1987357671 13
    -1760380366 -604895790  16
    -1057894078 -329706441  15
    -363772240  -1218064509 15
    1545317691  -300240831  14
    271304166   -900428132  21
    1208561582  273461468   16
    -1257783052 1069490639  16
    -1549884799 40157720    15
    -1514737808 -1818800021 17
    -1030569735 1859508545  15
    1310070992  880402584   18
    -1513092400 971613287   19
    -1993219517 354161779   16
    -10847170   -204018237  15
    -965377044  1488135032  14
    802471291   1094582308  22
    -539776032  -1021376555 15
    2088199751  2070302462  12
    -1271582124 64627614    19
    

    not so similar after 3-5 iterations he

    besides the standard Random implements a linear congruential RNG which is known not to be the best pseudo-random implementation in existence but the most efficient with memory (only one 64bit word for a period of 2^48)

    for the interested the multiplier is 0x5deece66dL and c is 0xbL

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

Sidebar

Related Questions

I am facing a problem while making Excel's LinEST function. My program goes like
I am having a strange problem while making an application in iPhone. The problem
While making some final tests of a class-library that I'm writing for Windows Mobile
While making a little Pong game in C++ OpenGL, I decided it'd be fun
Iam getting OutOfMemoryException while making remote method call. RemoteEntity.SetLocalStore(DATASET); passed value is dataset. Note
I noticed while making a program that a lot of my int type variables
I stumbled on a way to crash excel in Workbook_Open while making an .xla
I'm starting with Ruby, and while making some test samples, I've stumbled against an
I am making a fighting game in Flash and while I have everything running,
I've been making small scale projects for a while now. I haven't started a

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.