Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Is it possible for math.random to add to a specific number?

Asked by 3 years ago
Edited 3 years ago

Ok, this is sort of a dilemma for me. I've been searching through formulas and looking everywhere I can but I just can't seem to find an answer. So basically, I'm looping through all the players, and each player gets a random number. Sounds cool, ok.

Now, thats fine and all, but the dilemma comes in when the sum of all the player's number must equal a specific number.

Let use "I" to represent the amount of players in our for loop.

Lets say: Xx_FROSBITExX gets the number 25 and SomeOtherDude gets the number 50.

Now this is intended behaviour of math.random(x,y). But, is it possible for our numbers to add to 100. So If there 5 players. The sum of all 5 random numbers equals 100.

This may be represented by: 15, 25, 20, 35, 5. Notice how the 5 numbers (each player's random number adds to 100).

My script right now:

local totalweight = 100
local min = 1
local table = {}

local NumOfPlr 
game.Players.PlayerAdded:Connect(function(player)
    for i, plr in pairs(game.Players:GetPlayers()) do
        NumOfPlr = i
        table[plr] = ...how the heck can I figure this out
    end
end)
0
u could just add another block of text after the loop and there change the number of the select ppl Pitched_mobile 191 — 3y
0
Hmm, but that doesn't solve the dilemma though. I'm trying to make each player's random number add to a total number. Also can you explain what you mean? Xx_FROSTBITExX 116 — 3y
0
AHHHH I think I lost some braincells Xx_FROSTBITExX 116 — 3y
0
Nevermind, I Solve this goddamn dilemma. I'll update this post later. Xx_FROSTBITExX 116 — 3y

Answer this question