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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:08:56+00:00 2026-05-26T17:08:56+00:00

The following simple program in Java uses the java.util.Random class such that it always

  • 0

The following simple program in Java uses the java.util.Random class such that it always displays “hello world”. The code snippet can be seen below.

package nomain;

import java.util.Random;

final public class J
{
    public static String randomString(int seed)
    {
        Random rand = new Random(seed);
        StringBuilder sb = new StringBuilder();

        for(int i=0;;i++)
        {
            int n=rand.nextInt(27);
            if (n==0)
            {
                break;
            }
            sb.append((char) ('`'+n));
        }
        return sb.toString();
    }

    public static void main(String args[])
    {
        System.out.println(randomString(-229985452)+' '+randomString(-147909649));
    }
}

There is some surprise in that it always displays “hello world” even if the Random class is used that causes the random numbers to generate hence, the numbers should be changed on each run and the corresponding characters should be changed accordingly but it always displays only one stable string which is as mentioned above “hello world”. Why does it 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-26T17:08:56+00:00Added an answer on May 26, 2026 at 5:08 pm

    The answer is the parameter that’s being passed in. That’s used to seed the random number generator.

    Random rand = new Random(seed);
    

    PRNGs are not truly random – they are deterministic, but are designed to simulate randomness. For this reason they are better termed “pseudo-random number generators”.

    For a given seed, a PRNG will always generate the same number. It then likely uses its last result as an input to the next value, so by seeding the PRNG with a known value, you will always produce a known sequence of “random” numbers.

    The numbers -229985452 and -147909649 are known to be seeds which will cause that particular PRNG to produce a sequence of 5 numbers that can be interpreted as “hello” and “world”. If you were to change those numbers, you would get different 5-character sequences, but they would be the same for every run of the program, so long as the seed remains the same.

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

Sidebar

Related Questions

The following simple Java program appears to display the string Hello World through the
Consider the following simple code import java.util.*; public class MainTest<T extends Object1<?,?>> { List<T>
Given the following simple program: import wx class TestDraw(wx.Panel): def __init__(self,parent=None,id=-1): wx.Panel.__init__(self,parent,id,style=wx.TAB_TRAVERSAL) self.SetBackgroundColour(#FFFFFF) self.Bind(wx.EVT_PAINT,self.onPaint)
Consider the following simple C program that read a file into a buffer and
I need to write a simple program for work that does the following: read
I'm trying to compile the following simple DL library example code from Program-Library-HOWTO with
Let's look at the following simple code snippet in Java. interface Sum { abstract
I recently read that Java now sports initialisation blocks like the following: class C
I am trying to implement simple program in Java that will be used to
I have a simple Java program that allows a user to draw rectangles on

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.