Comments and answers for "probability for a Void"
http://answers.unity.com/questions/1838833/probability-for-a-void.html
The latest comments and answers for the question "probability for a Void"Comment by Earthshine on Earthshine's comment
http://answers.unity.com/comments/1838917/view.html
That's good to know. Thanks again.Fri, 28 May 2021 09:16:32 GMTEarthshineComment by Earthshine on Earthshine's comment
http://answers.unity.com/comments/1838915/view.html
This is correct.
I have forgotten about the overloads.
I'll fix my answer.
Thanks.Fri, 28 May 2021 09:14:41 GMTEarthshineComment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/1838913/view.html
Another minor detail:
This comparison:
if (f <= 0.1)
will promote / cast your float value `f` to a double since your `0.1` is a double as well. Since most floating point types in Unity are floats and not doubles you should get the habit of using float literal values like this:
if (f <= 0.1f)
This will actually do a float comparison since both operands are float values.Fri, 28 May 2021 09:09:59 GMTBunny83Comment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/1838912/view.html
Note that `Random.Range(0, 1); ` will always return `0`. There are two overloads of the Range function, one that takes integer parameters and returns an integer and one that takes float parameters and returns a float value. Furthermore the integer version has the upper limit exclusive while the float version hat the max value inclusive. So for example `Random.Range(0, 3)` can only return the values 0, 1 or 2 and never 3.
<br>
So you need to use float arguments to get a float result `Random.Range(0f, 1f)`. However if you just want a random float value between 0 and 1, you can simply read the [value property][1]
float f = Random.value;
This is equivalent to
float f = Random.Range(0f, 1f);
[1]: https://docs.unity3d.com/ScriptReference/Random-value.htmlFri, 28 May 2021 09:04:29 GMTBunny83Comment by Pb2323 on Pb2323's answer
http://answers.unity.com/comments/1838855/view.html
Thank you!Thu, 27 May 2021 22:00:22 GMTPb2323Answer by Earthshine
http://answers.unity.com/answers/1838847/view.html
There is a system to get a random number that you may use wherever you want.
public void TestYourLuck()
{
float f = Random.Range(0f, 1f); //this sets a new variable to a random number between 0 and 1
if (f <= 0.1f) GetMoney(); //10% chance to Get Money
else if (f >= 0.4f) WinAPrize(); //60% chance to Win a Prize
}
In this case GetMoney() and WinAPrize() are mutually exclusive.Thu, 27 May 2021 21:11:35 GMTEarthshine