Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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.

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. M39a9am3R 3210 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
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
Ad

Answer this question