I'm not remember many about random generation (there are a lot of them), but I 
remember many of probability, this is my especiality.

May be I could help letting you figure the problem.

> Hi,
> 
> I would like to add a new type of sequence in Tryton that will generate random
> but unique number.
> A simple solution will be to generate random number and compare it with
> already generated number (stored in a table). But there is the birthday
> paradox [1] that reduces the speed of this method.
> 
> An other way will be to store in a table every possible value (if the length
> of the number is fixed) and pick/remove one randomly. But here the generation
> of all values can be slow.
> 
> Is there anybody that knows a better way?
> 
Compare it with a box of numbered ball. The diference with the two ways as you 
propose here, is:

1) The first algorith is as having another box with infinite numbers (limited 
in a range), and you pickup from it box a ball and them look for a place in a 
numbered site, if the site is busy, them you repeat the previous step.

2) The second algorith is as having previously full the array, and them pickup 
the number from it.

Well clearly, the first have the problem of the colitions, that increase as the 
site is filling, and the second have the problem
 of the space that could be very high if the range is big.

As you can see the problem, is not the algorith, instead the range. As an 
example, if the range are the integer between 1 to 100, the problema as you 
have pick up 50% of the number in the first method is that the next ball have a 
chance of 50% of be an elegible ball, and the probabilitie will decrease very 
fast as you pick up more balls. In this case, I preffer the second algorith.
 But if you have a range of 1 to 10^32, the problem is that if you use the 
second method your computer could don't have enouf me
mory to do that.

I suggest, that you use the both methods, as a function of the size of the 
memory of the computer.

> 
> [1] http://en.wikipedia.org/wiki/Birthday_paradox
> 

As I understand the problem, the paradox is part of the problem as you explain, 
is more similar to the firts algorith, but have nothing in relation to the 
second algorith.

I suggest that you use any of the random generator that have python, my 
personal experience is that make a new one could be as usefull as make a new 
language, that is not the problem.

Regards.

-- 
Juan Fernando Jaramillo
Gte Tecnología
MIG Internacional
www.miginternacional.com

Attachment: signature.asc
Description: Digital signature

Reply via email to