How to strip characters out of uuid to use as a random seed

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

How to strip characters out of uuid to use as a random seed

Post by shawnblc » 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.

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: How to strip characters out of uuid to use as a random s

Post by sefrojones » Mon Jun 23, 2014 5:38 am

This worked for me, although I'm sure there's a fancier way to do it:

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

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: How to strip characters out of uuid to use as a random s

Post by shawnblc » Mon Jun 23, 2014 5:42 am

Thanks sefrojones. I'll give it a shot. Seems like it's doing the trick.

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: How to strip characters out of uuid to use as a random s

Post by sefrojones » Mon Jun 23, 2014 6:17 am

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.......

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: How to strip characters out of uuid to use as a random s

Post by shawnblc » Mon Jun 23, 2014 6:30 am

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.......

I tried your script so far and threw in a random text file to see what it looked like.

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"
Last edited by shawnblc on Mon Jun 23, 2014 6:33 am, edited 1 time in total.

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: How to strip characters out of uuid to use as a random s

Post by shawnblc » Mon Jun 23, 2014 6:31 am

In the dictionary they have an example with a 7 digit number, but don't mention a limit.

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: How to strip characters out of uuid to use as a random s

Post by sefrojones » Mon Jun 23, 2014 6:32 am

I think I've got this figured out, here's what I've got now, and it seems to be working great.

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
If the randomseed is longer than 9 digits, it will continually arrive at the same "random" number
edit: or so it seems to me

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: How to strip characters out of uuid to use as a random s

Post by shawnblc » Mon Jun 23, 2014 6:36 am

sefrojones wrote:I think I've got this figured out, here's what I've got now, and it seems to be working great.

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
If the randomseed is longer than 9 digits, it will continually arrive at the same "random" number
edit: or so it seems to me


Looks good. Gonna play with it. Like a kid with a new toy. lol

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: How to strip characters out of uuid to use as a random s

Post by shawnblc » Mon Jun 23, 2014 6:44 am

sefrojones wrote:I think I've got this figured out, here's what I've got now, and it seems to be working great.

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
If the randomseed is longer than 9 digits, it will continually arrive at the same "random" number
edit: or so it seems to me

Not so random for me. When I close and remove from memory and close out LC. Restart, I get the same results.

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: How to strip characters out of uuid to use as a random s

Post by sefrojones » Mon Jun 23, 2014 6:47 am

shawnblc wrote:

Looks good. Gonna play with it. Like a kid with a new toy. lol
Same here, I had never heard of uuid() until Simon mentioned it in your other post :D

--Sefro
Last edited by sefrojones on Mon Jun 23, 2014 6:57 am, edited 1 time in total.

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: How to strip characters out of uuid to use as a random s

Post by shawnblc » Mon Jun 23, 2014 6:53 am

sefrojones wrote:
shawnblc wrote:

Looks good. Gonna play with it. Like a kid with a new toy. lol
Same here, I had never hard of uuid() until Simon mentioned it in your other post :D

--Sefro
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. :)

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.

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: How to strip characters out of uuid to use as a random s

Post by sefrojones » Mon Jun 23, 2014 7:03 am

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.
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.

--Sefro

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: How to strip characters out of uuid to use as a random s

Post by [-hh] » Mon Jun 23, 2014 2:06 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 2:11 pm, edited 1 time in total.
shiftLock happens

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10053
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: How to strip characters out of uuid to use as a random s

Post by FourthWorld » Mon Jun 23, 2014 6:43 pm

@ shawnblc: The randomSeed property can be useful in cases where you want psuedorandomization across a repeatable series, but it not generally regarded as being able to increase the breadth of distribution for simulating true randomness. As Hermann suggested, the randseed setting the engine does at the beginning of each session is generally viewed as sufficient.

What problems did you encounter with the default randomseed?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

Re: How to strip characters out of uuid to use as a random s

Post by shawnblc » Tue Jun 24, 2014 5:08 am

FourthWorld wrote: What problems did you encounter with the default randomseed?
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.

Post Reply