Jump to content

random() vs gRandom()


mskod

Recommended Posts

gRandom is broken, if you want to use a random with normal distribution you can use 

But yeah, gRandom uses normal distribution which is one random distribution that very simplified basically gives more chance to numbers around the center (mean) and the deviation says how wide the field of more chance is :p. Normal random uses uniform distribution which means there's an even chance for every number

 

Edited by Reveance
  • Like 2
Link to comment
Share on other sites

1 hour ago, Reveance said:

gRandom is broken, if you want to use a random with normal distribution you can use 

But yeah, gRandom uses normal distribution which is one random distribution that very simplified basically gives more chance to numbers around the center (mean) and the deviation says how wide the field of more chance is :p. Normal random uses uniform distribution which means there's an even chance for every number

 

 

So if i use:

gRandom(50,10,0,100)

50 - mean

10 - stdDeviation

0 - min number

100 - max number

 

Will i get random numbers from 0 - 100, but mainly they will be from 40-60?

Link to comment
Share on other sites

17 minutes ago, mskod said:

 

So if i use:

gRandom(50,10,0,100)

50 - mean

10 - stdDeviation

0 - min number

100 - max number

 

Will i get random numbers from 0 - 100, but mainly they will be from 40-60?

You switched one param as mean is the second one, but correct :P... so gRandom(10, 50, 0, 100). This will result in the heigest chance to roll between 40 and 60. 99.7% of the values will lie between 20 and 80.

It might be easier to use gRandomBetween though, this automatically calculates the mean and deviation so that the above example would be equivalent to gRandomBetween(20, 80) with the difference of having a cap between 20, 80 instead of 0, 100

Edited by Reveance
  • Like 1
Link to comment
Share on other sites

Just going to clear up a few things.

A normal distribution is *not* a uniform distribution, and has a standard deviation, but is by no means composed of just a standard deviation (@Final). A normal distribution has a mean and standard deviation. 68% of the values in a normal distribution are within the first standard deviation (+/-); 95% are within the second (think it's 95.3% but I can't be sure); 99.7% are within the third.

gRandom(), which is now fixed  not fixed, utilizes a normal distribution, and is in no way a replacement for random(). random() uses a uniform distribution, in which each number has an equal probability of occurring, meaning gRandom() is *not* the same thing is based upon the details above. If you don't know how it's used, I wouldn't recommend using it.

Edit: It looks like gRandom() only uses the right side of the normal distribution.

Edited by Imateamcape
  • Like 1
Link to comment
Share on other sites

gRandom likely stands for gaussian random. 

Random - Most randomness, always random number within values.

gRandom - Still random, but more likely to be closer to the median value of the range.

Ex.

random(0, 100) - 30, 20, 5, 86, 40, 33, 99, 44, 33, 11, etc./

gRandom(0, 100) - 30, 44, 66, 55, 23, 10, 0, 75 (values closer to 50)

It's useful, because although statistically you have less variation, you can still get the full range. Which means you will normally have average values, but can still have outliers.

 

Link to comment
Share on other sites

22 minutes ago, Trees said:

gRandom likely stands for gaussian random. 

Random - Most randomness, always random number within values.

gRandom - Still random, but more likely to be closer to the median value of the range.

Ex.

random(0, 100) - 30, 20, 5, 86, 40, 33, 99, 44, 33, 11, etc./

gRandom(0, 100) - 30, 44, 66, 55, 23, 10, 0, 75 (values closer to 50)

It's useful, because although statistically you have less variation, you can still get the full range. Which means you will normally have average values, but can still have outliers.

 

No.

Edited by Imateamcape
Link to comment
Share on other sites

7 hours ago, Imateamcape said:

Just going to clear up a few things.

A normal distribution is *not* a uniform distribution, and has a standard deviation, but is by no means composed of just a standard deviation (@Final). A normal distribution has a mean and standard deviation. 68% of the values in a normal distribution are within the first standard deviation (+/-); 95% are within the second (think it's 95.3% but I can't be sure); 99.7% are within the third.

gRandom(), which is now fixed  not fixed, utilizes a normal distribution, and is in no way a replacement for random(). random() uses a uniform distribution, in which each number has an equal probability of occurring, meaning gRandom() is *not* the same thing is based upon the details above. If you don't know how it's used, I wouldn't recommend using it.

Edit: It looks like gRandom() only uses the right side of the normal distribution.

I mean we are here to educate him about the use of it, that was a lot of facts which could be found from my original series of posts.

  • Learn what standard deviation is.
  • Read the API Docs on the method: "Generates a random integer based on a normal distribution between 0 and a capped value based on a secret maximum deviation based on the standard deviation." .
  • You now know that the method uses normal distribution, has secret capped value and the value is always 0 or more. This means the positive (right) bound is only used so that negatives are impossible to appear.
  • Use this calculator to see how your numbers are effecting this method: http://davidmlane.com/hyperstat/z_table.html

TL;DR: gRandom uses normal distribution to calculate a number, this means we need a mean and an SD for a degree of deviation. The method then only selects from the right bound, we means the selected value can only be larger than the original value.

The reason for gRandom being broken is that the method only uses the right side of the possible values, meaning we can't get anything less than the original value. This is good as it is impossible to retrieve negative numbers from the method, however it means that in certain cases such as the example below, we can't access the left bound values, which is an issue in a lot of cases. I believe this was purposely implemented as gRandom in a lot of cases would actually return a negative value, when this value is attempting to impact things such as sleep, you can see why you wouldn't want a negative value in this case.

e8afdfc34e4b8d776e3595f1defd808d.png

 

 

 

 

Link to comment
Share on other sites

  • Alek locked this topic
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...