Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Simple question, how can I remove certain digits from a number?

Ok, so I made a script that generates smooth Roblox terrain, but it requires a random seed and I don't want to have the same map twice. So I'm getting my seed by

local diffnum = (tick()*10000)

local Seed = math.randomseed(diffnum)

This works, but the seed is so large that there is barely a difference between seeds.

Example =

->15622355456157

->15622355736583

What I want to do is remove the first 7 digits of the number so I get

->5456157

->5736583

Any help with this? Thanks.

1 comment

0

You can use some string manipulation and do something like tonumber(string.sub(tostring(diffnum),7)), which will get get the 7th character and on of diffnum and convert that returned string to a number again. Hopefully someone may produce a more extensive answer from this comment.

1 answer

✓ Accepted answer
local Number = 23123213 --example
local StringNumber = tostring(Number) --Makes the number a string so we can do :sub on it
local NeededOne = StringNumber:sub(StartingDigitWanted, EndingDigitWanted) --the numbers you want until it meets the digits you don't want
local NeededTwo = StringNumber:sub(StartingDigitWanted, EndingDigitWanted) --the numbers you want after the digit(s) is found
local FinalString = NeededOne .. NeededTwo --Puts the digits back together
local FinalNumber = tonumber(FinalString) --Makes the string back into a number

This discussion is preserved as it was. New answers, comments, and votes are closed.