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
 

Is it possible to...

Previous Thread :: Next Thread 
Agent00732 is not online. Agent00732
Joined: 23 Jan 2013
Total Posts: 8250
26 Jan 2015 02:45 PM
Generate a random letter from the alphabet using Scripting?
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
26 Jan 2015 02:48 PM
local arrayRandom = function (array)
return (#array > 0) and array[math.random(1, #array)] or nil;
end;



local stringToArray = function (str)
local array = { };
for i = 1, #str, 1 do
array[i] = str:sub(i, i);
end
return array;
end;



local alphabet = "abcdefghijklmnopqrstuvxyz";
local randomLetter = arrayRandom(stringToArray(alphabet));

print(randomLetter);
Report Abuse
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
26 Jan 2015 02:49 PM
local alphabet = {"a", "b", "c", "d", "e"}

local random = alphabet[math.random(#alphabet)]
Report Abuse
Agent00732 is not online. Agent00732
Joined: 23 Jan 2013
Total Posts: 8250
26 Jan 2015 02:51 PM
@Chief

Does that really work?
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
26 Jan 2015 02:51 PM
...
Just thought of any easier way:

local randomCharacter = function (upperCase)
return string.char((uppercase and "A" or "a"):byte() + math.random(26) - 1);
end;
Report Abuse
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
26 Jan 2015 02:52 PM
oh that's a quite creative solution drG

i like it
Report Abuse
Agent00732 is not online. Agent00732
Joined: 23 Jan 2013
Total Posts: 8250
26 Jan 2015 02:55 PM
Can you do something where it generates 3 letters, then 1 dash, then 3 numbers?
Kind of like a license plate.
Report Abuse
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
26 Jan 2015 02:57 PM
local str = randomCharacter(true) .. randomCharacter(true) .. randomCharacter(true) .. "-" .. math.random(1, 9) .. math.random(1, 9) .. math.random(1, 9)
Report Abuse
Scriptural is not online. Scriptural
Joined: 06 Sep 2013
Total Posts: 2979
26 Jan 2015 03:54 PM
Since its already been answered,
This isn't exactly what you asked for but I made this before and its kinda has to do with this

It makes a string of random lower and upper case letters, and numbers

local function random(x)
local output = ""
for _ = 1, (x or 16), 1 do
output = (output .. ((math.random(3) == 1) and math.random(0, 9) or string[math.random(2) == 1 and "upper" or "lower"](string.char(math.random(97, 122)))))
end
return output;
end

print(random()) -->random string 16 characters long
print(random(4)) -->random string 4 characters long
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