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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Bool randoming

Previous Thread :: Next Thread 
DarthStrantax is not online. DarthStrantax
Joined: 31 May 2011
Total Posts: 2610
10 Nov 2015 03:46 AM
Because I figure someone else might get annoyed at having to make a new bool-randoming function all the time.
require(318720512):Install(getfenv())
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
10 Nov 2015 04:55 AM
1==math.random(1,2) and true or false
Report Abuse
DarthStrantax is not online. DarthStrantax
Joined: 31 May 2011
Total Posts: 2610
10 Nov 2015 05:09 AM
true or false always returns true and math.random(1,2)==1 is what the module uses
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
10 Nov 2015 05:13 AM
But it doesn't always return true if you run it 5 times, it i bound to say false at least twice out of the five.
Report Abuse
DarthStrantax is not online. DarthStrantax
Joined: 31 May 2011
Total Posts: 2610
10 Nov 2015 05:16 AM
for i=1, 100 do print(true or false) end

all of them are true
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
10 Nov 2015 05:19 AM
No duh, because true is always the first to be valid in that statement....

for i=1, 100 do print(false or true) end


Always prints true also.
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
10 Nov 2015 05:19 AM
That has nothing to do with the method math.random.
Report Abuse
DarthStrantax is not online. DarthStrantax
Joined: 31 May 2011
Total Posts: 2610
10 Nov 2015 05:21 AM
why'd you put 'and true or false' then
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
10 Nov 2015 05:23 AM
1==math.random(1,2) and true or false

is the same as saying:

if 1==math.random(1,2) then
return true
else
return
false
end
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
10 Nov 2015 06:29 AM
== is a comparison operator and it returns a bool, so what Darth is saying is that 'and true or false' is unnecessary because == does that for you.
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
10 Nov 2015 06:35 AM
But it doesn't because it is a comparison to two instances which are "randomized". Look at what he said vs what I said, he was not comparing two random values, he was comparing two given values. There in-lies the difference.
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
10 Nov 2015 06:44 AM
I wish clockwork were here to straighten this out, like the old days
Report Abuse
LotsOfViolence is not online. LotsOfViolence
Joined: 29 Jun 2011
Total Posts: 8375
10 Nov 2015 06:47 AM
I prefer this for generating random numbers:

http://www.roblox.com/Random-org-generator-item?id=318598398

http://www.roblox.com/Lots-item?id=307049082http://www.roblox.com/Of-item?id=307039670http://www.roblox.com/Violence-item?id=307039720 http://www.roblox.com/Undertale-OST-Megalovania-item?id=301636384 | You're going to have a bad time.
Report Abuse
DevConsole is not online. DevConsole
Joined: 02 Jun 2008
Total Posts: 460
10 Nov 2015 09:01 AM
Clockwork shall be missed dearly.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
10 Nov 2015 02:36 PM
"1==math.random(1,2) and true or false"
Well first off you should know that it's left-right associative, that line is equiv. to this:

(1==math.random(1,2) and true) or false

If the condition does not fall through (1 is not equal to the random number) then you get false. "false and true" is false. 'and' returns the second operand given the first one is truey, and or returns the first operand given it's truey, else returns the second.

But that whole part is overdoing it, because the equivalence operator already returns a boolean, thus "1 == math.random(1,2)" is enough.
Report Abuse
dennysenpai is not online. dennysenpai
Joined: 07 Nov 2015
Total Posts: 8
10 Nov 2015 02:47 PM
This is a bit silly, isn't it?
Go learn your relational operands.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
10 Nov 2015 02:50 PM
go to hell veer, you sat addict
Report Abuse
cupcakescankill is not online. cupcakescankill
Joined: 24 Oct 2008
Total Posts: 13261
10 Nov 2015 02:58 PM
return math.random()>0.5
Report Abuse
Customality is not online. Customality
Joined: 11 Aug 2015
Total Posts: 590
10 Nov 2015 03:21 PM
^That will return more true than false. Use this: math.random() >= 0.5

Example:

if math.random() >= 0.5 then
print("true")
else
print("false")
end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
10 Nov 2015 03:42 PM
Or just < .5
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