in java

Random Number Generator

You might have wondered how predictable machines like computers can generate randomness. In reality, most random numbers used in computer programs are pseudo-random, which means they are generated in a predictable fashion using a mathematical formula. This is fine for many purposes, but it may not be random in the way you expect if you’re used to dice rolls, roulette wheels and lottery draws.

A list of random number is a numerical sequence as defined in Wiki – “A numeric sequence is said to be statistically random when it contains no recognizable patterns or regularities; sequences such as the results of an ideal die roll, or the digits of π (as far as we can tell) exhibit statistical randomness…

We can write a random number generator to generate a list of random numbers in a given range. A random number generator (often abbreviated as RNG) is a computational or physical device designed to generate a sequence of numbers or symbols that lack any pattern, i.e. appear random. Computer-based systems for random number generation are widely used, but often fall short of this goal, though they may meet some statistical tests for randomness intended to ensure that they do not have any easily discernible patterns. Methods for generating random results have existed since ancient times, including dice, coin flipping, the shuffling of playing cards, the use of yarrow stalks in the I Ching, and many other techniques.

Intuitively, an algorithmically random sequence (or random sequence) is an infinite sequence of binary digits that appears random to any algorithm. The definition applies equally well to sequences on any finite set of characters. Random sequences are key objects of study in algorithmic information theory.

I had written a small program in Java to generate a sequence of unique random numbers within 20.

The program is here: Random Number Generator

I am creating a List in which I intend to store unique number between 1 and 20 (inclusive). Firstly, I have to get hold of the object of class Random In order to store only unique numbers, first I check after generating the random number by


whether that number already exists in the list. And, thats it. You have got a list of unique random numbers between 1 and 20.

Blogged with Flock

Tags: , , , ,



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.