Mathematical percent coding (Read Desc)

This will sound confusing but pretty much the goal number is 0.000001 or lower (1 in 1,000,000). But the highest that can be generated with other rng is 100 so would could I calculate the percent how long the generated num is from 0.000001 so I could put it into a progress bar

1 Like

Please add more context. I feel this is an X and Y problem thing. It’s also very difficult to understand what you want from the way you worded it.

Pretty i want to see how far the generated num is from 0.000001 in percent so I could turn it into a progress bar

If you want to make a percentage system (bar), you should use division.

For example, if I had a number that represented xp (13), and the xp that represented the amount I needed to level up was 100, I would use this equation:

13 / 100 -- xp / maxXP

It’s a percentage, where maxXP is 100%. If you think your number is going to go over the boundaries, you can use math.clamp(), like this:

math.clamp(13 / 100, 0, 100)

This will clamp it, making sure it doesn’t go over 100, or under 0. Hopefully this helps.

the percent is based on how close the generated number is from 0.000001 when the highest num that can be generated is 100

if the highest number is 100 then the randomly generated number is gonna be the percentage value because the max value in a % is 100

I think this might be what you’re looking for:

local percent = 100 - (num / 1000000)

That should give you the percent of how close it is to that number

Try out my code, tell us the results.

I tested it but it doesnt quite work bc if my num was 0.1 then it would return as 99.999% which that’s definitely not true as 0.1 is pretty far from 0.000001

I see the issue, I’ll see if I can figure it out in my head

Try this in the meantime:

local percent = 100 - (num / 10000)

Returns the same thing. 99.9999% Ik its confusing sorry I hope you can understand though. I tried gpt but ai couldn’t figure it out either I was detailed too

Wait can’t you just do this:

100 - (num / 100)

The thing is i am trying to see how far my num that is generated from 0,100 is far from 0.000001

I finally understand what @CZXPEK was sharing. The code should be as simple as:

local percent = 100 - num

Sorry for the confusion

Ok, my number generator generates number from 0,100 and my goal num is 0.000001. I want to see the ‘progress’ how far the num that got generated is from 0.000001 so a num such as 0.00001 should be in the 90% ish. And a num such as 90 would be 1% ish bc that’s really far from 0.000001 and a num such as 100 would be 0% bc that’s the highest num that can be generated.

Could you not make the goal number 1,000,000? Doesnt really change anything, just makes it easier on our brains.

Adding 4 zeroes to your random number and dividing it by 1000000, then multiplying by 100 should give you your percentage value to work with

The main script is based on 1/1000000 which returns 0.000001

Could you make it 1000000/1? Also instead of dividing by 1000000 you could multiply it by 0.0001 if you cant

why is this?

extra text123

Forget my second sentence, but you could just use the strategy i said in comment 16, regardless of the number