I'm expecting some problems in creating big hashes, when running the following code.
(define Bigtree:Bigtree)
(new Tree 'Bigtree)
(define (fill-tree)
(for (x 1 20000)
(Bigtree (string (random 10 5)) (string (random 5 5)))
)
)
(define (show-size name)
(length name)
)
(define (show-tree name)
name
)
(fill-tree)
(show-size (Bigtree))
The code creates a hash and inserts 20000 random values into it.
On the first iteration (show-size) returns 20000
After running (fill-tree) another round the function (show-size) returns 39998
Doing this again will return 59995.
Am I doing something wrong with the hashes?
Cheers
Hilti
I'm a noob, but i would say that "(random 10 5)" is random but not unique, so it can happens that you get the same key twice or more.
Ormente is correct: the random function does not guarantee unique results. For that use the 'uuid' function, it guarantees true unique hash-able ids.
> (define BigTree:BigTree)
nil
> (dotimes (i 1000000) (BigTree (uuid) i))
999999
> (length (symbols BigTree))
1000001
>
Thank You Lutz! That works like a charm.
I didn't thought about the fact, that random is in this case not unique enough, because the way elements were missing was reproducible and regular.
Quote
...because the way elements were missing was reproducible and regular.
Each newLISP process starts out with the same pseudo random sequence. This repeatability of the random generator is needed and useful for debugging purposes. You can use the 'seed' function, to make a different random sequence.