Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Create a random number within a range without using random.range?

Discussion in 'Scripting' started by ackley14, Sep 2, 2015.

  1. ackley14

    ackley14

    Joined:
    Oct 31, 2014
    Posts:
    31
    yes...this is probably silly. I want to create a custom random number generator that accepts a range value plus some other bits, but i don't want to rely on unity's built in random.range function as i'd like to be able to tweak it to my liking. can anybody suggest a place i can find the source of random.range to learn how it works? or really any source of information regarding random number generators and how they work. i did look a bit already but all i could find...was actual random number generators online xD. thanks in advanced. hope this doesn't all sound too stupid xD
     
  2. Glockenbeat

    Glockenbeat

    Joined:
    Apr 24, 2012
    Posts:
    669
    ackley14 likes this.
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Wikipedia is a good place to start.

    https://en.m.wikipedia.org/wiki/Random_number_generation

    As far as I am aware Random is just a wrapper for System.Random. So you can use that as well.

    Building your own pseudorandom generator is not that crazy an idea. Tons of games do this to provide consistent randomness after game loads or across a network.
     
    ackley14 likes this.
  4. ackley14

    ackley14

    Joined:
    Oct 31, 2014
    Posts:
    31
    as far as tweaking, i simply mean adding and removing from the already existing algorythem to observe the results. Im a hands on learner, watching videos and reading articles is great for some but for me i like to mess with things untill i figure out exactly what makes them tick. so seeing the source algortyhem makes understanding these things much easier for me. again, i know its stupid but its just something i was hoping i could fiddle with
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    UnityEngine.Random is separate from System.Random.

    --Eric
     
  6. Duugu

    Duugu

    Joined:
    May 23, 2015
    Posts:
    241