Re: Need help to custom the rand function ,



On 31 jan, 14:29, The Natural Philosopher <a...@xxx> wrote:
Fred wrote:
Hi guys,

I was wondering how could i get a random number exemple between 1 and
100 but with n% of getting some value over a number x.

Thanks a lot in advance.

Fred

Never mind Jerry, No one else does.

So you want a random number from a weighted distribution?

Your spec doesn't contain quite enough data to formulate the formula,
since there are an infinite number of distributions that have N% over
value X..

One example, is that you first of all get a random number between 0 and
100: If this is greater than N, then select a random number greater than
X, else select one less than X.

So in pseudo code where RAND(X) returns a number between 0 and X-1...

if ((RAND(100))<N) THEN RETURN RAND(X) ELSE RETURN(X+RAND(100-X));

Thanks for the info, i wont mind on him then =)

Almost there with the code,

Let me add some real number in the exemple :

i know before the random what number i must have over let take 50 for
the exemple,
i also need the random to still pick between 0 and 100, but with a
chance of 60% (exemple) to draw something over 50 .

Thanks
.



Relevant Pages

  • Re: Need help to custom the rand function ,
    ... I was wondering how could i get a random number exemple between 1 and ... So you want a random number from a weighted distribution? ... Your spec doesn't contain quite enough data to formulate the formula, since there are an infinite number of distributions that have N% over value X.. ... So in pseudo code where RANDreturns a number between 0 and X-1... ...
    (comp.lang.php)
  • Re: Need help to custom the rand function ,
    ... Your spec doesn't contain quite enough data to formulate the formula, ... This is not a god way to get a weighted distribution (and the OP is ... floating point number and apply a transformation function to it. ...
    (comp.lang.php)
  • Re: Need help to custom the rand function ,
    ... So you want a random number from a weighted distribution? ... Your spec doesn't contain quite enough data to formulate the formula, ... The problam is he wnats SOME form of weighted distribution, ..as evinced by the actual spec. ... Continuous transformations are quite difficult but since for a ...
    (comp.lang.php)