generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How would i make probability?

Previous Thread :: Next Thread 
llaserx is online. llaserx
Joined: 10 Dec 2011
Total Posts: 53069
10 Mar 2017 09:18 AM
espically one that doesnt need percents that needs to add up to 100%


Report Abuse
HumanXerxes is not online. HumanXerxes
Joined: 17 Apr 2011
Total Posts: 1351
10 Mar 2017 09:56 AM
Is this what you're talking about?

Probability = 50
if math.random(1,100)<=Probability then
Report Abuse
llaserx is online. llaserx
Joined: 10 Dec 2011
Total Posts: 53069
10 Mar 2017 10:26 AM
not rlly


Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
10 Mar 2017 10:46 AM
Give things weights, sum the weights, roll a die, and then figure out what bucket you're in. Do something with specific thing.


sumOfWeights = 0
for thing, weight do
sumOfWeights = sumOfWeights+weight
end
local event = math.random(sumOfWeights)
for thing, weight do
if event <= weight then
-- do something with the thing
break
else
event = event-weight
end
end
Report Abuse
RogueMage is not online. RogueMage
Joined: 28 Jan 2012
Total Posts: 1235
10 Mar 2017 11:28 AM
I call it math

You should've learned this in Algebra II or Pre-Calculus
Report Abuse
llaserx is online. llaserx
Joined: 10 Dec 2011
Total Posts: 53069
10 Mar 2017 07:36 PM
ya because everyone has those 2 classes o________________o


Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
10 Mar 2017 07:39 PM


local stuff = {
{10,'apple'},
{20.5,'potato'},
{35.5,'pear'},
{34,'mango'}
}

table.sort(stuff,function(a,b) return a[1] < b[1] end)

local num = math.random() * 100

local old = 0

local chosen

for i=1, #stuff do
old = old + stuff[i][1]
if old <= num then
chosen = stuff[i][2]
break
end
end

print(chosen)

something like that should work


Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
10 Mar 2017 07:40 PM
you can change the math.random() * 100 to math.random() * totalchanceofallthingsinthetable


Report Abuse
llaserx is online. llaserx
Joined: 10 Dec 2011
Total Posts: 53069
11 Mar 2017 09:48 AM
it seems like everyone suggests <= for this


thx
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
11 Mar 2017 11:48 AM
@Disillusions that will always pick the first thing in your table.
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
11 Mar 2017 05:43 PM
*num <= old


Report Abuse
KapKing47 is not online. KapKing47
Joined: 09 Sep 2012
Total Posts: 5522
11 Mar 2017 05:54 PM
Could u plz be more specific, what kinda of probability would u like exactly?


Report Abuse
breifmanny is online. breifmanny
Joined: 23 Dec 2011
Total Posts: 341
11 Mar 2017 06:40 PM
Simpler version:


local probability = 20

chances = math.random (1, # probability)
print(chances)
end


or something like that idk
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image