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: El little puzzle for yous.

Previous Thread :: Next Thread 
Kirbykid02 is not online. Kirbykid02
Joined: 18 May 2009
Total Posts: 2671
23 Feb 2014 08:09 AM
Seeing as this subforum is a decaying piece of inorganic matter, I'd like to freshen things up with a challenge.

Challenge is : to write (in the shortest amount of characters) a function to randomly choose 0 or 1 favouring 1 twice as much as 0.

Example (of what would work but wouldn't win):

function randomizeTheNumbersPlease()
local randomNumber = math.random(1,3)
if randomNumber >= 2 then
print(1)
elseif randomNumber == 1 then
print(0)
end
end
Report Abuse
AndroidKitKat is not online. AndroidKitKat
Joined: 21 Sep 2013
Total Posts: 1525
23 Feb 2014 08:10 AM
print(math.random(1,3)> 1 and 1 or 0)
Report Abuse
AndroidKitKat is not online. AndroidKitKat
Joined: 21 Sep 2013
Total Posts: 1525
23 Feb 2014 08:10 AM
print(math.min(math.random(0,2),1)
Report Abuse
OneTrueGodTheHolyCow is not online. OneTrueGodTheHolyCow
Joined: 24 Oct 2013
Total Posts: 9350
23 Feb 2014 08:11 AM
print(math.random()>0.25 and 1 or 0)

AW MAN THIS ISN'T WHERE I PARKED MY CAR
Report Abuse
AndroidKitKat is not online. AndroidKitKat
Joined: 21 Sep 2013
Total Posts: 1525
23 Feb 2014 08:12 AM
^ >(1/3)
Report Abuse
OneTrueGodTheHolyCow is not online. OneTrueGodTheHolyCow
Joined: 24 Oct 2013
Total Posts: 9350
23 Feb 2014 08:13 AM
:O Android noob detected

also he said to write a function

w=function()return math.random()>0.25 and 1 or 0 end

AW MAN THIS ISN'T WHERE I PARKED MY CAR
Report Abuse
AndroidKitKat is not online. AndroidKitKat
Joined: 21 Sep 2013
Total Posts: 1525
23 Feb 2014 08:17 AM
function()print(math.min(math.random(0,2),1))
Report Abuse
AndroidKitKat is not online. AndroidKitKat
Joined: 21 Sep 2013
Total Posts: 1525
23 Feb 2014 08:18 AM
function()print(math.random()>0.25 and 1 or 0)end
Report Abuse
AndroidKitKat is not online. AndroidKitKat
Joined: 21 Sep 2013
Total Posts: 1525
23 Feb 2014 08:18 AM
^ lol wrong code, sorry.

function()print(math.min(math.random(0,2),1))end
Report Abuse
AndroidKitKat is not online. AndroidKitKat
Joined: 21 Sep 2013
Total Posts: 1525
23 Feb 2014 08:23 AM
function()print(math.ceil(math.random()-1/3))end
Report Abuse
Kirbykid02 is not online. Kirbykid02
Joined: 18 May 2009
Total Posts: 2671
23 Feb 2014 08:24 AM
function()print(math.abs(math.random(-1,1))end
Report Abuse
AndroidKitKat is not online. AndroidKitKat
Joined: 21 Sep 2013
Total Posts: 1525
23 Feb 2014 08:27 AM
I hate you
Report Abuse
AndroidKitKat is not online. AndroidKitKat
Joined: 21 Sep 2013
Total Posts: 1525
23 Feb 2014 08:39 AM
function{}print({0,1,1}[math.random(1,3)])end
Report Abuse
AndroidKitKat is not online. AndroidKitKat
Joined: 21 Sep 2013
Total Posts: 1525
23 Feb 2014 08:42 AM
just realized you can't do that
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
23 Feb 2014 08:43 AM
@Android: You need ( ) around the { }.



@OP: You didn't say it had to be in Lua :P
->math.abs math.random -1,1
Report Abuse
AndroidKitKat is not online. AndroidKitKat
Joined: 21 Sep 2013
Total Posts: 1525
23 Feb 2014 08:47 AM
cout << rand%3 ? 1 : 0
Report Abuse
AndroidKitKat is not online. AndroidKitKat
Joined: 21 Sep 2013
Total Posts: 1525
23 Feb 2014 08:48 AM
^ reason why I use semicolons on Lua
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
23 Feb 2014 08:55 AM
Aha!

local function a()
return 1-(math.random(0,2)%2);
end

local values = {[0] = 0; [1] = 0};
local total = 1000;

for i = 1, total, 1 do
local x = a();
values[x] = values[x] + 1;
end

for i = 0, 1, 1 do
print(("%i: %3i %2.2f"):format(i, values[i], (100 / total) * values[i]));
end


0: 331 33.10
1: 669 66.9
Report Abuse
AndroidKitKat is not online. AndroidKitKat
Joined: 21 Sep 2013
Total Posts: 1525
23 Feb 2014 09:01 AM
droid, you really deserve your main group. ._.
Report Abuse
Kirbykid02 is not online. Kirbykid02
Joined: 18 May 2009
Total Posts: 2671
23 Feb 2014 09:11 AM
So few characters....
Report Abuse
AndroidKitKat is not online. AndroidKitKat
Joined: 21 Sep 2013
Total Posts: 1525
23 Feb 2014 09:18 AM
function()print(math.random(1,3)%2)end
Report Abuse
AndroidKitKat is not online. AndroidKitKat
Joined: 21 Sep 2013
Total Posts: 1525
23 Feb 2014 09:20 AM
I stand on the shoulders of giants. :P
Report Abuse
OneTrueGodTheHolyCow is not online. OneTrueGodTheHolyCow
Joined: 24 Oct 2013
Total Posts: 9350
23 Feb 2014 10:11 AM
hacker detected

AW MAN THIS ISN'T WHERE I PARKED MY CAR
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
23 Feb 2014 10:26 AM
print(1)
Guaranteed to be random for most cases.
Report Abuse
200AB is not online. 200AB
Joined: 24 Aug 2010
Total Posts: 1604
23 Feb 2014 10:37 AM
function() print(math.random(1,1000)*100/20-100%5)))) end

...did i win yet??
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