Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can we use distributions with ::math::random??

Status
Not open for further replies.

RajVerma

Programmer
Jun 11, 2003
62
DE
hi,

I use the built-in random number generator with the command,
[::math::random 1 101] which gives a number between, and including, 1 and 100. Now, I want to get the random number in this range in such a way that the probability of getting 1 is more than the probability of getting a 100.

The bigger the number in the range the lesser the probability it shud be. so is there a way to use some kind of distributions along side the random number generator to get the desired result??

thnx,
Raj.
 
The only way I can think to do this is to nest the RNGs. Let's say you have a set of ten RNG functions. The first is 1 to 10, the second 1 to 20, the third 1 to 30, and so on. Then you have a "master" RNG that generates a number from 1 to 10. You use the output of the master to choose which of the set of 10 to invoke. That should increase the chances as you want, no?

_________________
Bob Rashkin
rrashkin@csc.com
 
hi bob,
thanx for the suggestion. seems like yours is also a good idea. actually I tried as follows:

set randNumber [::math::random $min $max]

set lowRandNumber1 [::math::random $min $randNumber]
set lowRandNumber2 [::math::random $min $lowRandNumber1]
...
set lowRandNumber9 [::math::random $min $lowRandNumber8]
set lowRandNumber10 [::math::random $min $lowRandNumber9]
set highRandNumber1 [::math::random $randNumber $max]
set highRandNumber2 [::math::random $highRandNumber1 $max]
...
set highRandNumber9 [::math::random $highRandNumber8 $max]
set highRandNumber10 [::math::random $highRandNumber9 $max]

so with these 20 lines, I cud get able to cover whole of the range from $min to $max with some sort of distribution.

cheers,
Raj.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top