Skip to main content
added 538 characters in body
Source Link
LifGwaethrakindo
  • 1.4k
  • 2
  • 15
  • 27

It could be because you need to set a random seed before using the random range, considering this similar problem.

Although I think that UnityEngine.Random's seed is deprecated after 5.3, so maybe use the System.Random?

Example with UnityEngine.Random:

public class Example : MonoBehaviour
{
    public float bias;

    public void GenerateRandom()
    {
#if !UNITY_EDITOR
        Random.seed = Input.acceleration.magnitude * (1f + bias); /// Maybe you could use the accelerometer to get the seed.
#endif

        float randomNumber = Random.Range(0.0f, 100.0f);
        Debug.Log(randomNumber.ToString());
    }
}

Example with System.Random:

public class SystemExample : MonoBehaviour
{
    public int maxRange;

    public void GenerateRandom()
    {
        /// Maybe you could use the accelerometer to get the seed.
        int seed = (int)(Input.acceleration.magnitude * (1f + bias));
        Random rng = new Random(seed);

        /// Returns a non-negative random integer that is less than the specified maximum.
        int randomIndex = Random.Next(maxRange);
        Debug.Log(randomIndex.ToString());
    }
}

To know more about random seeds. Hope it helps.

It could be because you need to set a random seed before using the random range, considering this similar problem.

Although I think that UnityEngine.Random's seed is deprecated after 5.3, so maybe use the System.Random?

public class Example : MonoBehaviour
{
    public float bias;

    public void GenerateRandom()
    {
#if !UNITY_EDITOR
        Random.seed = Input.acceleration.magnitude * (1f + bias); /// Maybe you could use the accelerometer to get the seed.
#endif

        float randomNumber = Random.Range(0.0f, 100.0f);
        Debug.Log(randomNumber.ToString());
    }
}

To know more about random seeds. Hope it helps.

It could be because you need to set a random seed before using the random range, considering this similar problem.

Although I think that UnityEngine.Random's seed is deprecated after 5.3, so maybe use the System.Random?

Example with UnityEngine.Random:

public class Example : MonoBehaviour
{
    public float bias;

    public void GenerateRandom()
    {
#if !UNITY_EDITOR
        Random.seed = Input.acceleration.magnitude * (1f + bias); /// Maybe you could use the accelerometer to get the seed.
#endif

        float randomNumber = Random.Range(0.0f, 100.0f);
        Debug.Log(randomNumber.ToString());
    }
}

Example with System.Random:

public class SystemExample : MonoBehaviour
{
    public int maxRange;

    public void GenerateRandom()
    {
        /// Maybe you could use the accelerometer to get the seed.
        int seed = (int)(Input.acceleration.magnitude * (1f + bias));
        Random rng = new Random(seed);

        /// Returns a non-negative random integer that is less than the specified maximum.
        int randomIndex = Random.Next(maxRange);
        Debug.Log(randomIndex.ToString());
    }
}

To know more about random seeds. Hope it helps.

Source Link
LifGwaethrakindo
  • 1.4k
  • 2
  • 15
  • 27

It could be because you need to set a random seed before using the random range, considering this similar problem.

Although I think that UnityEngine.Random's seed is deprecated after 5.3, so maybe use the System.Random?

public class Example : MonoBehaviour
{
    public float bias;

    public void GenerateRandom()
    {
#if !UNITY_EDITOR
        Random.seed = Input.acceleration.magnitude * (1f + bias); /// Maybe you could use the accelerometer to get the seed.
#endif

        float randomNumber = Random.Range(0.0f, 100.0f);
        Debug.Log(randomNumber.ToString());
    }
}

To know more about random seeds. Hope it helps.