r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Graham
7-Jan-2009
[12009x2]
I usually seed with a precise time value
so, random/seed now looks okay to me
Henrik
7-Jan-2009
[12011]
Graham, if you ever (ever) need to do that under win98, you must 
be careful, because time precision is much lower there.
Graham
7-Jan-2009
[12012]
Umm... not sure if my stuff runs under win98!
Henrik
7-Jan-2009
[12013x2]
hence, you can get the same value, if you do it again after 1/10th 
or 1/100th of a second.
just so you know. :-)
Graham
7-Jan-2009
[12015x2]
what do people do to create a UUID?
This is what I am doing .. hope it's okay!


make-uuid: func [ pid ][

    form checksum/secure rejoin [ "" random/secure 10000000 form now/precise 
    pid ]
]

where pid is the id for the customer in the crm
Henrik
7-Jan-2009
[12017]
I think it's OK. I use:

checksum/secure random to-string now/precise


Never had a duplicate with that, but I would want a fast one for 
performance built into REBOL.
Sunanda
7-Jan-2009
[12018]
But, just in case of duplicates, you need to write that to a file.

If the value already exists on that file, try again. Repeat until 
a unique number emerges.
Henrik
7-Jan-2009
[12019]
sunanda and when there is a million values?
Graham
7-Jan-2009
[12020]
Hmm... mine is already time based.  I doubt my hard drive IO is faster 
than that!
Henrik
7-Jan-2009
[12021]
As an experiment I tried a plain 'checksum on now/precise, because 
I wanted a shorter numeric ID that a user could type in. On 5000 
users there were 3 collisions, so.. no good.
Sunanda
7-Jan-2009
[12022]
The question to ask is not:

-- how would I ever get duplicates (you'll easily find that out when 
something goes wrong -- it's called debugging).
Instead ask:
-- how damaging would duplicates be?

If very damaging, then make sure your system is robust -- not simply 
that it looks so.
Graham
7-Jan-2009
[12023]
the only problem arises if the pc clock is set back.
Sunanda
7-Jan-2009
[12024]
Or if the clock gets stuck!
Graham
7-Jan-2009
[12025]
but then I synchronize the user's clock to NIST time at the start 
of the session.
Henrik
7-Jan-2009
[12026]
The only way is to generate a stupid long ID to reduce the likelihood 
of a duplicate by a factor of... astronomical.
Graham
7-Jan-2009
[12027x2]
I know lots of people use UUIDs for database records .. wonder what 
their algorithm is.
I don't .... I use an autoincrementing field ... but think in retrospect 
I should have used UUIDs instead so I can merge databases
Gregg
7-Jan-2009
[12029]
There are a lot of ways to do it. Some people use the GUID API on 
Windows. Some use a high-low model, kind of like you are by including 
the PID. Combining clock (with setback checking), counter, machine 
info, and a key (like PID), is plenty good.
Nicolas
7-Jan-2009
[12030x2]
Noticing that many people use two words to time things, I made a 
little timer function.
time: func [s] [
    t: now/time/precise
    if do s [now/time/precise - t]
]
Steeve
7-Jan-2009
[12032]
pffff, i give you a medal
Nicolas
7-Jan-2009
[12033x2]
sorry.
but why do people use two words instead of one?
Steeve
7-Jan-2009
[12035]
because
btiffin
7-Jan-2009
[12036]
Historical?   start (set) and then end (report).    R3 has a dt (delta-time) 
function built in and some other nice profiling words.
Gabriele
8-Jan-2009
[12037x2]
Re: Random: there is some confusion here! /SECURE is *not* an alternative 
to /SEED. You still need a seed as well for both algorithms.
The issue is not "duplicates" but predictability of the sequence. 
How many numbers you need to know before you can predict what the 
next number is going to be. /SECURE is supposed to be much more difficult 
to predict.
Henrik
8-Jan-2009
[12039]
so it's more an issue of predictability than actual level of randomness?
Gabriele
8-Jan-2009
[12040]
predictability = level of randomness :)
Henrik
8-Jan-2009
[12041]
really? perhaps there's no correlation between randomness and risk 
of collision.
Gabriele
8-Jan-2009
[12042]
is a dice "random"?
Henrik
8-Jan-2009
[12043]
I would say it is, but I may be asking the wrong thing of randomness, 
namely a minimal risk of collisions.
Gabriele
8-Jan-2009
[12044]
what is the probability of getting the same number twice in a row? 
or twice in a sequence of 3 rolls? or twice in a sequence of 100 
rolls?
Henrik
8-Jan-2009
[12045]
yes, I see your point.
Gabriele
8-Jan-2009
[12046x4]
the risk of collision depends only on the number of possible outcomes, 
assuming a uniform distribution
and indeed, for UUIDs, it may be ok to be predictable as long as 
you can reduce collisions.
for example, if you had a clock with a precision of 10^-5 seconds, 
and you knew it was impossible to have more than 10000 requests per 
seconds, then you would be fine to just use your clock as your UUID.
the result would be the least random possible, but still unique.
Henrik
8-Jan-2009
[12050x3]
true
I suppose then also if you want a short (6-8 digits) user input ID, 
one you must type in your browser, it's best to use a sequential 
ID accompanied by a passcode.
so there is a sequential part and a random part.
Sunanda
8-Jan-2009
[12053]
Generate a random id, then check if is not already issued. If it 
is, try again.
That works for me!

(Though there is the remote risk that my code starts getting slower 
aftre many thousand years of continuous operation, when clashes start 
becoming likely :-)
Pekr
8-Jan-2009
[12054x2]
I used simple randomized copy/part upon checksum/secure now/time/precise. 
Worked so far ...
Is there an easy way of how to detach message from imported email?
Pavel
8-Jan-2009
[12056]
Probably detach.r from rebol.org?
Pekr
8-Jan-2009
[12057]
yes, I am just looking at it and wondering, why import-email does 
not have such refinement :-)
Geomol
8-Jan-2009
[12058]
Henrik, Rebolek posted this code in the "View" group last year to 
illustrate the difference between random and random/secure:

img: make image! 512x512 
repeat i 512 [
	repeat j 512 [
		either i < 256 [
			if 2 = random 2 [
				img/(as-pair i - 1 j - 1): 255.255.255
			]			
		][
			if 2 = random/secure 2 [
				img/(as-pair i - 1 j - 1): 255.255.255
			]
		]
	]
]


view layout [image img across text "RANDOM" tab tab tab text "RANDOM/SECURE"]