wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arrays" Watch "Arrays" New topic
Author

Arrays

Nickk Singhal
Greenhorn

Joined: Dec 09, 2011
Posts: 4
how to generate random number without using random class
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3429
    
  12
You should read NotACodeMill and then update your post.

NB - this was a reply to the original post which was just a question copied from a book/exam paper/whatever and if i remember properly had nothing to do with random numbers.


Joanne
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

You could implement your own random number generator. But beware that it is not easy to create "good" random numbers (random numbers which are truly random, or which at least have a statistical distribution that comes close to being really random). Several algorithms have been invented to generate pseudo-random numbers; do some research to learn more about them.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

Or just use Math.random(). It generates a double value between 0.0 (inclusive) and 1.0 (exclusive), so multiply it by X and cast to int to get an int value between 0 (inclusive) and X (exclusive).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Arrays
 
Similar Threads
Adding Arrays
Subtract arrays
conversion from int[] to long[]
Arrays
Question on similar & identical of Objects