Advertisement
Short_Circuit

Random Name Picker

Jan 18th, 2014
84
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2. Random Name Picker by Short Circuit
  3. For use in...
  4. well...
  5. anything that needs random name picking.
  6. ]]--
  7.  
  8.  
  9. --Who all is participating in this?
  10. function getNames()
  11.     --Fancy entry prompts FTW
  12.     print("How many entries do you have?: ")
  13.     --Get the number of entries to enter
  14.     ent = io.read()
  15.     makeSomeRoom(1)
  16.     --Init that table!
  17.     names = {}
  18.     --Make a loop for us, will 'ya?
  19.     for i = 1,ent do
  20.         --Format the input prompt nicely for the user. :)
  21.         print("Name in slot " .. i .. ": ")
  22.         --Gotta be fancy 'bout that io.read() stuff.
  23.         names[i] = io.read()
  24.         makeSomeRoom(1)
  25.     end
  26. end
  27.  
  28. --Let's make things random up in here!
  29. function genRandomNumber(val)
  30.     --True randomness seed.
  31.     math.randomseed( tonumber(tostring(os.time()):reverse():sub(1,6)) )
  32.     --Generate the winning number!
  33.     winner = math.random(val)
  34. end
  35.  
  36. --Now that we know who won, let's tell the user!
  37. function printNameWinner()
  38.     --Call the random number gen- gonna want the number. :p
  39.     genRandomNumber(ent)
  40.     --Use that number to pick the winner! :D
  41.     print(names[winner] .. " is the winner! :D")
  42. end
  43.  
  44. --OCD functions start here
  45. --OCD pause function
  46. function pauseAndWait()
  47.     --DOS/Windows-like pause text.
  48.     print("Press the Enter key to continue...")
  49.     --Waits for Enter to be pressed.
  50.     io.read()
  51. end
  52.  
  53. --OCD "make some spaces" function
  54. function makeSomeRoom(spaces)
  55.     i = 1
  56.     for i = 1, spaces do
  57.         print("")
  58.     end
  59. end
  60.  
  61. --Now we start it all up!
  62. function initScript()
  63.     --GIVE ME CREDIT :D
  64.     print('----------------------------------')
  65.     print(":                                :")
  66.     print(":       Random Name Picker       :")
  67.     print(":    Written by Short Circuit    :")
  68.     print(":                                :")
  69.     print("----------------------------------")
  70.     makeSomeRoom(4)
  71.     --Get the input from the user.
  72.     getNames()
  73.     makeSomeRoom(2)
  74.     --Print the winner! :D
  75.     printNameWinner()
  76.     --Make some room! :P
  77.     makeSomeRoom(2)
  78.     --Pauses the script to let users copy the output.
  79.     pauseAndWait()
  80. end
  81.  
  82. --[[
  83. Okay. Everything is done...
  84. Oh, wait... I wrapped the init code in a function!
  85. Let's go ahead and call that, shall we?
  86. ]]--
  87. initScript()
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement