- Home /
is there a way to make Random.Range be more Random?
Hello
i found that when i debug Random.Range from 1 to 500 in Update(), all values appear the same number of times.
is there a way to make the values more random or better random function?
i hope you understood my question.
Can you post your code here? I tried out this and everything worked fine void Update () { Debug.Log(Random.Range(0, 500)); }
Also, do you mean that every number logged to console is the same?
yea same code but i used 50 in this example to save time waiting. check this image, almost all of them fall in the range of 80~90, i dont see any of them for example, 20 times while another one is 100 or something like that
That's exactly the behaviour you would expect from randomly selecting 1-50. Perhaps it would help if you explained what results you expected or what you were using this for.
For instance, for damage I would suggest reducing randomness using a dice like system as explained http://www.redblobgames.com/articles/probability/damage-rolls.html.
Answer by flagDiZero · May 15, 2018 at 03:07 PM
Hi!
here it is (unity 5) or this (actual)
You can istantiate the seed (or the init) state every time that you need a random. Maybe with the delta time or something changing
Answer by Topthink · May 15, 2018 at 10:48 PM
Try this, it makes Random a bit more random. Good luck.
Random.InitState ((int)System.DateTime.Now.Ticks); // Makes things more random
Answer by The_Icaruz · May 16, 2018 at 05:25 AM
So if I'm not wrong the values on the left of your screenshot are the random numbers you get and not the one on the right.
I see your numbers are between 1 and 50 like you set it up in your code.
If I misunderstood your question just let me know.
Your answer
Follow this Question
Related Questions
Random.Range is not changing? 1 Answer
Random.Range doesnt work anymore 4 Answers
How to randomize answers? 1 Answer
How to make Random.Range() step by a certain amount? 1 Answer
Randomize texture within prefab 0 Answers