---
title: "Why does this code using random strings print “hello world”?"  
description: "Why does this code using random strings print “hello world”?"  
author: "Anonymous User"  
published: 2015-05-06  
updated: 2015-05-06  
canonical: https://www.mindstick.com/forum/23190/why-does-this-code-using-random-strings-print-hello-world  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# Why does this code using random strings print “hello world”?

I came across this piece of [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii), and found it rather interesting. The following [print](https://www.mindstick.com/blog/301752/types-of-3d-printing-technology) statement would print "[hello world](https://www.mindstick.com/forum/12912/how-to-show-hello-world-backbone-marionette-js)". Could [anyone explain](https://www.mindstick.com/forum/34220/can-anyone-explain-me-about-off-page-activity) this?\

```
System.out.println(randomString(-229985452) + " " + randomString(-147909649));
```

And randomString() looks like this

```
public static String randomString(int i){    Random ran = new Random(i);    StringBuilder sb = new StringBuilder();    while (true)    {        int k = ran.nextInt(27);        if (k == 0)            break;        sb.append((char)('`' + k));    }    return sb.toString();}
```

## Replies

### Reply by Anonymous User

When an instance of java.util.Random is constructed with a specific seed parameter (in this case -229985452 or -147909649), it follows the random number generation algorithm beginning with that seed value.\
Every Random constructed with the same seed will generate the same pattern of numbers every time.


---

Original Source: https://www.mindstick.com/forum/23190/why-does-this-code-using-random-strings-print-hello-world

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
