Random Generator Question

Hi guys,

I'm wanting to know how would I go about creating some form of random where I have range of 3 number (say in an simple array). And I want to say the likely hood of picking the number at index 0 is 25%, index 1 is 50%, index 2 is 75%.

With the Java random generator class it seems that picking the numbers wtih the range is done by an equal fairness. So, how do i customise the randomness so the likely is more weighted to choose certain numbers in the range over others.

Many thanks.

Message was edited by:

_Visionary_

[567 byte] By [_Visionary_a] at [2007-11-27 2:43:15]
# 1

Maybe its the easy way, make a switch case, and make a random int of 4, and something like this:

case 1:

"string 50%"

case 2:

"same string 50%!

case 3:

"a string of 25%"

case 4:

"the other 25% string"

is logic and maybe a stupid solution, but effective.

big_rota at 2007-7-12 3:08:40 > top of Java-index,Java Essentials,Java Programming...
# 2

> ...

> And I want to say the likely hood of picking the number at index

> 0 is 25%, index 1 is 50%, index 2 is 75%.

A total of 125%?

Anyway, here's a hint:

0 = 25%

1 = 30%

2 = 40%

3 = 5%

Get a random number N between 1 and 100. If N is between

- 1 and 25, return 0

- 25 and 55, return 1

- 55 and 95, return 2

- 95 and 100, return 3

prometheuzza at 2007-7-12 3:08:40 > top of Java-index,Java Essentials,Java Programming...
# 3
> A total of 125%?Since when does 25 + 50 + 75 = 125? ;-)
CaptainMorgan08a at 2007-7-12 3:08:40 > top of Java-index,Java Essentials,Java Programming...
# 4
haha may be i had an error in the sum, but the point was clear.
big_rota at 2007-7-12 3:08:40 > top of Java-index,Java Essentials,Java Programming...
# 5
> > A total of 125%?> > Since when does 25 + 50 + 75 = 125? ;-)Holy crap!; )
prometheuzza at 2007-7-12 3:08:40 > top of Java-index,Java Essentials,Java Programming...