# Random range (556215)

**URL:** <https://discussions.unity.com/t/random-range-556215/556215>\
**Category:** Scripting\
**Tags:** Scripting\
**Created:** [November 8, 2014, 3:32am UTC](https://discussions.unity.com/t/random-range-556215/556215 "2014-11-08T03:32:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tricky1980](https://avatars.discourse-cdn.com/v4/letter/t/c57346/32.png) [@Tricky1980](https://discussions.unity.com/u/Tricky1980)\
**Post date:** [November 8, 2014, 3:32am UTC](https://discussions.unity.com/t/random-range-556215/556215/1 "2014-11-08T03:32:56Z")

</div>

Does anybody have an idea how I can get a random number, let’s say between 1 and a 100, but where higher numbers have a lower frequency of coming up?

---

<div class="post-metadata">

**Author:** ![hpjohn](https://avatars.discourse-cdn.com/v4/letter/h/b782af/32.png) [@hpjohn](https://discussions.unity.com/u/hpjohn)\
**Post date:** [November 8, 2014, 4:01am UTC](https://discussions.unity.com/t/random-range-556215/556215/2 "2014-11-08T04:01:00Z")

</div>

You need to do maths  
Use some equation to change a linear input 1-\>100 into a non-linear output 1-\>100  
for example (x\*0.1)^2  
blue is the linear case, horizontal axis is input, vertical is output  
 ![](https://europe1.discourse-cdn.com/unity/original/4X/1/5/f/15f3492b67a0a83c200aab2032ac02fd0cd06d0d.gif)  
In script would look like

```csharp
int value = (int)( Mathf.Pow(Random.Range(0f, 100f) * 0.1f, 2f) );

```

Note: this is marginally simpler if you work in the 0 → 1 range

---

<div class="post-metadata">

**Author:** ![Tricky1980](https://avatars.discourse-cdn.com/v4/letter/t/c57346/32.png) [@Tricky1980](https://discussions.unity.com/u/Tricky1980)\
**Post date:** [November 8, 2014, 5:16am UTC](https://discussions.unity.com/t/random-range-556215/556215/3 "2014-11-08T05:16:40Z")

</div>

Thanks for the answer and the math lesson!
