Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arrays

 
Nickk Singhal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to generate random number without using random class
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic