- Home /
Random.Range doesnt work anymore
Hello guys, i have a problem with Random.range. Until yesterday all works as expected but today no. I always get the same number... In the following script for example i always get 0.4072546
If i use this script in another project it works well but in my actual project no, so i think that could be a project setting... Have you any idea?
using UnityEngine;
public class provaScript : MonoBehaviour {
void Update () {
Debug.Log(Random.Range(0f, 1f));
}
}
UPDATE
f i make a new scene inside the same project all works as expected
The only reason why random would always return the same value is if the seed is always reset to the same value. Check all the scripts for calls to Random.InitState()
or Random.state
(see scripting reference for more info), both of which can affect the random generation state. Based on your update, the script must be in the scene that produces the unexpected behaviour.
Answer by Happeloy · May 15, 2018 at 03:04 PM
The only thing I can think of is that you somewhere, in some script, is setting the Random.Seed to the same value each frame. Could that be the case?
I searched seed and InitState in the whole project... nothing
Answer by kskjadav007 · May 15, 2018 at 01:26 PM
try using Random.Range(0f, 5f)
Answer by BGOKMEN14 · May 15, 2018 at 01:27 PM
Hello @flagDiZero,
It works perfectly fine with me. What I would do is delete the script and create a new one with the exact same code. Let me know if it works or not.
Answer by flagDiZero · May 15, 2018 at 02:57 PM
@BGOKMEN14 I got exactly the same
same code works fine in unity 2017.3.1f
tell me your unity version
is script attached to multiple object ?
unity 2018.1.0 and 2017.2.0. The script is attached only on one object
working for me in 2017.2
Debug.Log(Random.Range(0f, 5f));
is this working ???
Your answer
Follow this Question
Related Questions
Random.Range is not changing? 1 Answer
How to randomize answers? 1 Answer
How to make Random.Range() step by a certain amount? 1 Answer
is there a way to make Random.Range be more Random? 3 Answers
Random Generation Algorithm Error 3 Answers