How to strip characters out of uuid to use as a random seed
Posted: Mon Jun 23, 2014 5:28 am
How to strip characters out of uuid to use as a random seed? So that I'm only left with numbers, since randomseed only uses numbers.
Questions and answers about the LiveCode platform.
https://www.forums.livecode.com/
Code: Select all
on mouseUp
put empty into tSeed
put uuid() into tVar
repeat with x=1 to the number of characters in tVar
if char x of tvar is a number then
put char x of tvar after tSeed
else
put empty into char x of tvar
end if
end repeat
answer tseed
end mouseUp
sefrojones wrote:Is there a limit to the length of a randomseed? I'm trying to use (basically) the same script as i posted above, and for some reason when I set the randomseed to tSeed, it doesn't take. Any ideas?
edit: It seems like you can't set the randomseed to any number longer than 9 digits.......
Code: Select all
put empty into tSeed
put uuid() into tVar
repeat with x=1 to the number of characters in tVar
if char x of tvar is a number then
put char x of tvar after tSeed
else
put empty into char x of tvar
end if
end repeat
## I wonder if this is even random
put any line of URL ("http://domain.com/totalrandom.txt") into tLine1
put tLine1 into field "fldRandom1"
Code: Select all
on mouseUp
put uuid() into tVar
repeat with x=1 to the number of characters in tVar
if char x of tvar is a number then
put char x of tvar after tSeed
if the number of chars of tSeed >=9 then exit repeat
end if
end repeat
replace space with empty in tSeed
set the randomseed to tSeed
Answer "randomseed:" && the randomseed&cr& "random:"&&random(100) & cr & "uuid:"&&tvar
end mouseUp
sefrojones wrote:I think I've got this figured out, here's what I've got now, and it seems to be working great.
If the randomseed is longer than 9 digits, it will continually arrive at the same "random" numberCode: Select all
on mouseUp put uuid() into tVar repeat with x=1 to the number of characters in tVar if char x of tvar is a number then put char x of tvar after tSeed if the number of chars of tSeed >=9 then exit repeat end if end repeat replace space with empty in tSeed set the randomseed to tSeed Answer "randomseed:" && the randomseed&cr& "random:"&&random(100) & cr & "uuid:"&&tvar end mouseUp
edit: or so it seems to me
sefrojones wrote:I think I've got this figured out, here's what I've got now, and it seems to be working great.
If the randomseed is longer than 9 digits, it will continually arrive at the same "random" numberCode: Select all
on mouseUp put uuid() into tVar repeat with x=1 to the number of characters in tVar if char x of tvar is a number then put char x of tvar after tSeed if the number of chars of tSeed >=9 then exit repeat end if end repeat replace space with empty in tSeed set the randomseed to tSeed Answer "randomseed:" && the randomseed&cr& "random:"&&random(100) & cr & "uuid:"&&tvar end mouseUp
edit: or so it seems to me
Same here, I had never heard of uuid() until Simon mentioned it in your other postshawnblc wrote:
Looks good. Gonna play with it. Like a kid with a new toy. lol
Know whatcha mean, I've heard of uuid's and namespaces (I definitely don't understand them), but I don't do this for a living like some guys on here. Just a hobby. With any luck one day I'll make something a few find useful and they might just be willing to pay for it.sefrojones wrote:Same here, I had never hard of uuid() until Simon mentioned it in your other postshawnblc wrote:
Looks good. Gonna play with it. Like a kid with a new toy. lol
--Sefro
That's weird, when i try to use my first script it works to seperate the numbers form the UUID but when I try to set the randomseed to Tseed, It will only use tSeed as the randomseed if it is less than 9 digits. If it is more than 9 digits it will not throw an error, but the randomseed is set to a different number (the same one every time), and random(100) will give the same result every time. When i set it to only use the first 9 digits of tSeed, it seemingly works fine......This is on Ubuntu 14.04 (which I am very new to) I will probably play around with this a bit more in windows 7 tomorrow.shawnblc wrote: I was getting better results with what you had the first time around. Seemed a lot more random, even when I went from reading lines from a 10,000 line file to one with less than 20 lines.
When using randsomseed, closing the program & removing from memory, then restarting the stack I'd get the same repeated line using randomseed or using any line. Both on OSX 10.93 and Windows 7 (vmware). Anytime my stack is called I'd like it truly random. Not a repeat of the same sequence.FourthWorld wrote: What problems did you encounter with the default randomseed?