• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can I get a random number , between two randoms?  RSS feed

 
Ertan Hasani
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys , i need to know if i could get a random number between two randoms ?
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not necessarily. For example it's impossible to find a random integer between 4 and 5 (because there aren't any integers between 4 and 5).
 
Esteban Herrera
author
Ranch Hand
Posts: 42
1
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is what you're after:



In the case Paul mentions, the result would be either 4 or 5. It makes sense to my because I consider between inclusive. Hope it helps.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to create a new Random object each time you generate a random number. Just create one Random object and use it to generate all the random numbers.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ertan, please BeForthrightWhenCrossPostingToOtherSites
http://www.java-forums.org/new-java/94816-can-i-get-random-number-between-two-randoms.html
 
Ertan Hasani
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why this is showing as a error?

 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"No suitable method found for max(Random, int)"

That tells you EXACTLY what the problem is. You are calling the max method, and passing it a "Random" object and an "int". If you look at the API for the Math class (or even the rest of the text box), it tells you that the only methods that exist take two ints, two longs, two floats, or two doubles.

You are passing in an object used to CREATE numbers, not an actual number.

 
Ertan Hasani
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:"No suitable method found for max(Random, int)"

That tells you EXACTLY what the problem is. You are calling the max method, and passing it a "Random" object and an "int". If you look at the API for the Math class (or even the rest of the text box), it tells you that the only methods that exist take two ints, two longs, two floats, or two doubles.

You are passing in an object used to CREATE numbers, not an actual number.


So what should I do to get a random ( generator1, randomIndex1))
 
Esteban Herrera
author
Ranch Hand
Posts: 42
1
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ertan,

I have the feeling your confusion is caused by a typo.

According to the image you posted, you wrote

It should be
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Esteban Herrera wrote:According to the image you posted, you wrote

It should be


And that typo would be much easier to catch if the variables were named better. generator for a Random object, that seems fair enough. But generator1 for an int? Why? That makes no sense.
 
Ertan Hasani
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Esteban Herrera wrote:Hi Ertan,

I have the feeling your confusion is caused by a typo.

According to the image you posted, you wrote

It should be


Thank you bro
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!