Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Java Tutorials


 

 

Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Java Notes

Random numbers - Introduction

[an error occurred while processing this directive]

When to use random numbers

There are many types of programs that use random numbers. Game programs use them to create situations that are not always the same every time a player is in the same situation, or a deck of cards must be shuffled. Simulations usually use random numbers. You might want to use random numbers to change the appearance of something -- screensavers are an example of use. There are many other uses also.

Type, Range, and Distribution

When you generate random numbers, you need to decide which type you need (eg, int or double), what range you need (minimum to maximum), and how they are distributed. There are two common types of distributions: uniform and normal (equivalent to Gaussian). In a uniform distribution all numbers in the range are equally likely to be produced.

How can a computer generate a random number?

Computers are deterministic -- they do the same thing whenever they have the same input. Therefore, in some way it is impossible for a computer to compute a truly random number. But the methods that are used generate sequences of numbers that meet the statistical requirements of randomness. Because the numbers are not truly random, they are sometimes referred to as pseudorandom numbers. These random number generates will produce exactly the same sequence of pseudorandom numbers if they start with the same initial value. This initial value is called the seed.

If we start a program with the same random seed, we will get the same sequence of numbers. The default seed is the current time in milliseconds since 1970. This works very well, but you might want to set the seed so that the sequence can be reproduced when you are testing your program.

Related pages

  1. Random numbers - API
  2. Random Numbers - shuffling
  3. java.sun.com/docs/books/effective/excursion-random.html, Excursion 1: Random Thoughts by Joshua Bloch, author of Effective Java.
Ask programming questions?

 

 

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name

 

 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.

[an error occurred while processing this directive]