Custom RNG Command Help

I know there’s a lot of smart people on here so Im gonna ask for some help

I really want a command for nightbot where it randomly generates a number 0-12 but the higher the number, the harder it gets to obtain that number, so while 1-3 is common, once you approach past 5-6, it becomes very hard to get, and by the time you get to 12, its virtually impossible, like odds of winning the lottery a thousand times or something.

What should be the percent chance of rolling a number in each number range?

Hey @willzanimationz!

So I thought about a solution to your command, since you didn’t give the percent chance of rolling a each number it gave me a lot of space to be creative!

My idea is to use Euler’s number, this way it gets increasingly harder to get selected numbers.

But then, after analyzing the results of my tests with your problematic in mind, turns out it would give me more 12 than 0, which I would have noticed before if I paid more attention to the ln(x) and e^(x) plots. It was the opposite of what we want here. Time to start over? No.

I looked if a simple function that was the vertical mirror of ln(x) existed, but I couldn’t find anything, so I decided to go with what I had, never mind if it doesn’t look as fancy as I wanted it to look like.


So here’s the command to generate a random number between 0 and 12, where it becomes increasingly harder to get the higher numbers:

$(eval r=Math.round(Math.log(Math.floor(Math.random()*Math.round(Math.exp(12)))+1)); r==0?`12`:r==1?`11`:r==2?`10`:r==3?`9`:r==4?`8`:r==5?`7`:r==6?`6`:r==7?`5`:r==8?`4`:r==9?`3`:r==10?`2`:r==11?`1`:r==12?`0`:``;)

Basically we generate a random number between 0 and 12, and then since we get more 12 than 0, we invert by saying if the random number is 0, give a 12, etc.

With that in mind, here are the percentage of chance to get each number:

0 → ~39%
1 → ~38%
2 → ~14%
3 → ~5%
4 → ~2%
5 → ~0.7%
6 → ~0.3%
7 → ~0.1%
8 → ~0.04%
9 → ~0.01%
10 → ~0.005%
11 → ~0.002%
12 → ~0.0006%

If you wanted to generate a random number between 1 and 12 instead, here’s the command:

$(eval r=Math.round(Math.log(Math.floor(Math.random()*Math.round(Math.exp(11)))+1)); r==0?`12`:r==1?`11`:r==2?`10`:r==3?`9`:r==4?`8`:r==5?`7`:r==6?`6`:r==7?`5`:r==8?`4`:r==9?`3`:r==10?`2`:r==11?`1`:``;)

In which case the percentage of chance to get each number are:

1 → ~63%
2 → ~23%
3 → ~9%
4 → ~3%
5 → ~1%
6 → ~0.4%
7 → ~0.2%
8 → ~0.06%
9 → ~0.02%
10 → ~0.008%
11 → ~0.003%
12 → ~0.001%

If you want to have number ranges, so the numbers in the first range have the same percentage of chance, and it get’s harder for higher ranges, here’s what you can do:

  1. choose your ranges and count them
  2. flip the results, 0 happens the less often, NUMBER_OF_RANGES-1 happens the most often
  3. for ranges with multiple numbers in it, generate randomly one of these with: Math.floor(Math.random()*(MAX-MIN+1))+MIN

So here’s the command to fit all your needs:

$(eval r=Math.round(Math.log(Math.floor(Math.random()*Math.round(Math.exp(NUMBER_OF_RANGES-1)))+1)); r==0?`HARDEST_RANGE_TO_REACH`:r==1?`SECOND_HARDEST_RANGE_TO_REACH`: ... :r==NUMBER_OF_RANGES-1?`EASIEST_RANGE_TO_REACH`:``;)

If I find a fancier way to do it, meaning if I find the function that is the vertical mirror of ln(x), I’ll post an update, as it would be exciting to get the results directly, and not having to flip them.


Example:
I want a command that generate numbers, but it’s harder to get the higher ones, my ranges are: 1-3 / 4-6 / 7-8 / 9-10 / 11 / 12, so it’s really easy to get a number from 1 to 3, slightly less easy to get a number from 4 to 6, etc. and definitely harder to get the number 12.
In total I have 6 ranges, so NUMBER_OF_RANGES-1 = 5
So my command will look like this:

$(eval r=r=Math.round(Math.log(Math.floor(Math.random()*Math.round(Math.exp(5)))+1)); r==0?`12`:r==1?`11`:r==2?`${Math.floor(Math.random()*2)+9}`:r==3?`${Math.floor(Math.random()*2)+7}`:r==4?`${Math.floor(Math.random()*3)+4}`:r==5?`${Math.floor(Math.random()*3)+1}`:``;)

In the end the percentage of chance to get each range of numbers are:

1-3 → ~63%
4-6 → ~23%
7-8 → ~9%
9-10 → ~3%
11 → ~1%
12 → ~0.5%

Wow this is amazing thank you!! ;D

1 Like

I just thought of a way to make it harder to get the higher range if the odds are too high for your taste.


If we take the last example, we had the following ranges with these odds:

1-3 → ~63%
4-6 → ~23%
7-8 → ~9%
9-10 → ~3%
11 → ~1%
12 → ~0.5%

However, if you’d like 12 to have lower odds, let’s say ~0.001% like in the command to generate a random number between 1 and 12, we need 12 categories, but we only have 6 in our case.

The key is to double, or triple some of these categories, in the order you decide, so for example we can have the following categories in this order:
1-3 / 1-3 / 1-3 / 4-6 / 4-6 / 4-6 / 7-8 / 7-8 / 9-10 / 9-10 / 11 / 12
Which would give the following odds:

1-3 → ~95%
4-6 → ~4.4%
7-8 → ~0.26%
9-10 → ~0.028%
11 → ~0.003%
12 → ~0.001%

Now, what if I don’t like these odds? Well, simply switch the order, for example:
1-3 / 4-6 / 4-6 / 4-6 / 1-3 / 1-3 / 7-8 / 7-8 / 9-10 / 9-10 / 11 / 12
Would give the following odds:

1-3 → ~64.4%
4-6 → ~35%
7-8 → ~0.26%
9-10 → ~0.028%
11 → ~0.003%
12 → ~0.001%

With the last set of ranges and odds in mind, this would give the following command:

$(eval r=Math.round(Math.log(Math.floor(Math.random()*Math.round(Math.exp(11)))+1)); r==0?`12`:r==1?`11`:r==2?`${Math.floor(Math.random()*2)+9}`:r==3?`${Math.floor(Math.random()*2)+9}`:r==4?`${Math.floor(Math.random()*2)+7}`:r==5?`${Math.floor(Math.random()*2)+7}`:r==6?`${Math.floor(Math.random()*3)+1}`:r==7?`${Math.floor(Math.random()*3)+1}`:r==8?`${Math.floor(Math.random()*3)+4}`:r==9?`${Math.floor(Math.random()*3)+4}`:r==10?`${Math.floor(Math.random()*3)+4}`:r==11?`${Math.floor(Math.random()*3)+1}`:``;)

You can easily see how you can advantage some ranges over others, any combination is possible, you select the order that will advantage the ranges you’d like to have high odds and disadvantage the ones you want to have very low odds.
For example you could make something where it’s easy to get the extremums, and less likely to get the middle numbers.
Take a look at these ranges: 1-3 / 7 / 4-6, this would give these odds:

1-3 → ~66.66%
7 → ~25%
4-6 → ~8.33%

The command would look like this:

$(eval r=Math.round(Math.log(Math.floor(Math.random()*Math.round(Math.exp(2)))+1)); r==0?`${Math.floor(Math.random()*3)+4}`:r==1?`7`:r==2?`${Math.floor(Math.random()*3)+1}`:``;)

And for people wondering the odds for each ranges, I calculated them up to 15 ranges.

I don’t think it’s worth going higher since you’ll already get odds of 0.0001% or 1/1,000,000 at 14 ranges, I included the odds of 15 ranges because there’s an interesting change.


2 ranges - lowest odds: 25%

Range 01 | r = 1  | 75%
Range 02 | r = 0  | 25%

3 ranges - lowest odds: 8.3333%

Range 01 | r = 2  | 66.6667%
Range 02 | r = 1  | 25%
Range 03 | r = 0  | 8.3333%

4 ranges - lowest odds: 3.0303%

Range 01 | r = 3  | 63.6364%
Range 02 | r = 2  | 24.2424%
Range 03 | r = 1  | 9.0909%
Range 04 | r = 0  | 3.0303%

5 ranges - lowest odds: 1.1111%

Range 01 | r = 4  | 63.3333%
Range 02 | r = 3  | 23.3333%
Range 03 | r = 2  | 8.8889%
Range 04 | r = 1  | 3.3333%
Range 05 | r = 0  | 1.1111%

6 ranges - lowest odds: 0.4098%

Range 01 | r = 5  | 63.1148%
Range 02 | r = 4  | 23.3607%
Range 03 | r = 3  | 8.6066%
Range 04 | r = 2  | 3.2787%
Range 05 | r = 1  | 1.2295%
Range 06 | r = 0  | 0.4098%

7 ranges - lowest odds: 0.1504%

Range 01 | r = 6  | 63.3083%
Range 02 | r = 5  | 23.1579%
Range 03 | r = 4  | 8.5714%
Range 04 | r = 3  | 3.1579%
Range 05 | r = 2  | 1.2030%
Range 06 | r = 1  | 0.4511%
Range 07 | r = 0  | 0.1504%

8 ranges - lowest odds: 0.0553%

Range 01 | r = 7  | 63.2190%
Range 02 | r = 6  | 23.2854%
Range 03 | r = 5  | 8.5177%
Range 04 | r = 4  | 3.1527%
Range 05 | r = 3  | 1.1615%
Range 06 | r = 2  | 0.4425%
Range 07 | r = 1  | 0.1659%
Range 08 | r = 0  | 0.0553%

9 ranges - lowest odds: 0.0204%

Range 01 | r = 8  | 63.2072%
Range 02 | r = 7  | 23.2601%
Range 03 | r = 6  | 8.5674%
Range 04 | r = 5  | 3.1339%
Range 05 | r = 4  | 1.1600%
Range 06 | r = 3  | 0.4274%
Range 07 | r = 2  | 0.1628%
Range 08 | r = 1  | 0.0611%
Range 09 | r = 0  | 0.0204%

10 ranges - lowest odds: 0.0075%

Range 01 | r = 9  | 63.2158%
Range 02 | r = 8  | 23.2502%
Range 03 | r = 7  | 8.5560%
Range 04 | r = 6  | 3.1514%
Range 05 | r = 5  | 1.1528%
Range 06 | r = 4  | 0.4267%
Range 07 | r = 3  | 0.1572%
Range 08 | r = 2  | 0.0599%
Range 09 | r = 1  | 0.0225%
Range 10 | r = 0  | 0.0075%

11 ranges - lowest odds: 0.0028%

Range 01 | r = 10 | 63.2135%
Range 02 | r = 9  | 23.2549%
Range 03 | r = 8  | 8.5529%
Range 04 | r = 7  | 3.1475%
Range 05 | r = 6  | 1.1593%
Range 06 | r = 5  | 0.4241%
Range 07 | r = 4  | 0.1570%
Range 08 | r = 3  | 0.0578%
Range 09 | r = 2  | 0.0220%
Range 10 | r = 1  | 0.0083%
Range 11 | r = 0  | 0.0028%

12 ranges - lowest odds: 0.0010%

Range 01 | r = 11 | 63.2123%
Range 02 | r = 10 | 23.2548%
Range 03 | r = 9  | 8.5549%
Range 04 | r = 8  | 3.1469%
Range 05 | r = 7  | 1.1579%
Range 06 | r = 6  | 0.4265%
Range 07 | r = 5  | 0.1560%
Range 08 | r = 4  | 0.0577%
Range 09 | r = 3  | 0.0213%
Range 10 | r = 2  | 0.0081%
Range 11 | r = 1  | 0.0030%
Range 12 | r = 0  | 0.0010%

13 ranges - lowest odds: 0.0004%

Range 01 | r = 12 | 63.2123%
Range 02 | r = 11 | 23.2543%
Range 03 | r = 10 | 8.5549%
Range 04 | r = 9  | 3.1472%
Range 05 | r = 8  | 1.1575%
Range 06 | r = 7  | 0.4260%
Range 07 | r = 6  | 0.1569%
Range 08 | r = 5  | 0.0574%
Range 09 | r = 4  | 0.0212%
Range 10 | r = 3  | 0.0078%
Range 11 | r = 2  | 0.0030%
Range 12 | r = 1  | 0.0011%
Range 13 | r = 0  | 0.0004%

14 ranges - lowest odds: 0.0001%

Range 01 | r = 13 | 63.2121%
Range 02 | r = 12 | 23.2545%
Range 03 | r = 11 | 8.5548%
Range 04 | r = 10 | 3.1472%
Range 05 | r = 9  | 1.1578%
Range 06 | r = 8  | 0.4258%
Range 07 | r = 7  | 0.1567%
Range 08 | r = 6  | 0.0577%
Range 09 | r = 5  | 0.0211%
Range 10 | r = 4  | 0.0078%
Range 11 | r = 3  | 0.0029%
Range 12 | r = 2  | 0.0011%
Range 13 | r = 1  | 0.0004%
Range 14 | r = 0  | 0.0001%

15 ranges - lowest odds: 0.0001%

Range 01 | r = 14 | 39.3470%
Range 02 | r = 13 | 38.3401%
Range 03 | r = 12 | 14.1046%
Range 04 | r = 11 | 5.1887%
Range 05 | r = 10 | 1.9089%
Range 06 | r = 9  | 0.7022%
Range 07 | r = 8  | 0.2583%
Range 08 | r = 7  | 0.0950%
Range 09 | r = 6  | 0.0350%
Range 10 | r = 5  | 0.0128%
Range 11 | r = 4  | 0.0047%
Range 12 | r = 3  | 0.0017%
Range 13 | r = 2  | 0.0007%
Range 14 | r = 1  | 0.0002%
Range 15 | r = 0  | 0.0001%

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.