Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
TheEndless
Channel Surfer

Re: Generating GUID using BrightScript

"RokuMarkn" wrote:
In many applications, one does not have access to all previously generated GUIDs, but I can't say if that's true for the OP.

If Rnd returned truly random numbers, TheEndless' algorithm would be pretty much as good as a real GUID. It's possible, although extremely unlikely, for real GUIDs, produced according to the RFC, to produce duplicates too. In TheEndless' algorithm, since Rnd is called in a predictable sequence, collisions are only as unlikely as two scripts starting with the same Rnd internal state, which actually isn't all that unlikely. Rnd is not a cryptographically strong RNG and it's probably not a good idea to use it as such.

--Mark

Mark, what is the seed for Rnd on the Roku? I assumed it would be the current tick (or something as equally high resolution), in which case, the likelihood of duplicate generation across a 32 character sequence seems extremely unlikely.

Your point about Rnd not being cryptographically strong is understood, but the OP just said he needed a unique ID in the form of a GUID. He never really expanded on why he needed them, hence my question about why he'd be generating them often enough that duplication was a concern.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
RokuMarkn
Visitor

Re: Generating GUID using BrightScript

It does use something like the current tick, which isn't a very good seed. All it takes is for two boxes to boot at close to the same time and they could generate identical GUIDs. Granted, it does have to be VERY close to the same time, but depending on the cost of a collision, it may be a risk that the developer doesn't want to take. Which gets back to your question to the OP about what the GUIDs will be used for.

--Mark
0 Kudos
RokuMarkn
Visitor

Re: Generating GUID using BrightScript

I'm glad to report that I was mistaken about the seed for Rnd. It's not based on the time, so a sequence of Rnds, while not of cryptographic quality, is not very likely to collide.

--Mark
0 Kudos
jaxim
Visitor

Re: Generating GUID using BrightScript

any update on this? I have a need to generate a GUID in a Roku app. Can someone share the GUID generator function?
0 Kudos
RokuMarkn
Visitor

Re: Generating GUID using BrightScript

The function that TheEndless posted in this thread should work fine.  In the extremely unlikely event that you need your GUID formatted as a version 4 GUID, you would force the first digit of the third group to be a "4" and the first digit of the fourth group to be 8,9,A or B.

--Mark
0 Kudos
EnTerr
Roku Guru

Re: Generating GUID using BrightScript

"jaxim" wrote:
any update on this? I have a need to generate a GUID in a Roku app. Can someone share the GUID generator function?

Have a look at roDeviceInfo.getRandomUUID()
0 Kudos