Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to Make RAND() issue UNIQUE numbers?
Message
De
08/12/1997 05:55:35
 
 
À
05/12/1997 20:51:17
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00063913
Message ID:
00064400
Vues:
89
>>>Correct! But you can generate random numbers to pick records from the table. As soon as a record is picked, you flag it or delete it... :)
>>>
>>>Don't take me seriously here! I'm only joking! You don't need to use the long way if you know the short one. :)
>>>
>>>Vlad
>>>
>>>>A quick test of SYS(2015) gave me:
>>>>
>>>>_RQ91824UH
>>>>_RQ91824UI
>>>>_RQ91824UJ
>>>>_RQ91824UK
>>>>_RQ91824UL
>>>>_RQ91824UM
>>>>_RQ91824UN
>>>>_RQ91824UO
>>>>
>>>>This appears to be unique but sequential, so if I then sort on this number, the result is not randomized. In fact the order may not change at all...
>>>>
>>>>thx
>>>>
>>>>>>No... not at all...
>>>>>>
>>>>>>RAND() works fine, even with the additional test for uniqueness. I was just wondering if there was an internal function to achieve the same thing.
>>>>>
>>>>>Well, you can use the sys(2015) to get unique keys. Of course, you can convert chars to digits. This will give you unique numbers, but not random numbers. I wouldn't use this!
>>>>>
>>>>>Vlad
>>>>>
>>>>>>>As I said: if it's random, then it's not unique. So, it doesn't matter what method you use to get random numbers, you must test them to be sure you choose each number only once.
>>>>>>>
>>>>>>>Why? Why is RAND() not good? Too slow?
>>>>>>>
>>>>>>>Vlad
>>>>>>>
>>hi,
>>
>>>>>>>>Is there another way to shuffle a list of phone numbers so that they are random?
>>>>>>>>
>>>>>>>>thx
>>>>>>>>
>>>>>>>>>If it's unique, it's not random! And if it's random than it's not necessary unique! :)
>>>>>>>>>
>>>>>>>>>Vlad
>>>>>>>>>
>>>>>>>>>>Yeah, I was just hoping for something like RAND(,U) <-- a unique parameter.
>>>>>>>>>>
>>>>>>>>>>I'm told that C++'s RAND() function returns unique numbers...
>>>>>>>>>>
>>>>>>>>>>Oh well, I did the SEEK to verify uniqueness and it works fine.
>>>>>>>>>>
>>>>>>>>>>Thanks
>>>>>>>>>>
>>>>>>>>>>>This is normal. Random numbers are not unique.
>>>>>>>>>>>
>>>>>>>>>>>Each time you generate a new number you must do a SEEK and add it only if it is not already in your table.
>>>>>>>>>>>
>>>>>>>>>>>Vlad
>>>>>>>>>>>
>>>>>>>>>>>>I fill a file having 12000 records with 'random' numbers. Index on number unique
>>>>>>>>>>>>shows only 7550 unique numbers
>>>>>>>>>>>>
>>>>>>>>>>>>>What's the problem? Ie: What doesn't work?
>>>>>>>>>>>>>
>>>>>>>>>>>>>Vlad
>>>>>>>>>>>>>
>>>>>>>>>>>>>>We are using RAND() to create a random sampling of a phone number file so
>>>>>>>>>>>>>>we need unique numbers so we don't re-use phone numbers
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>Any way?
>>
>>hi,
>>the way is to make unique or primary index in the table,
>>generate random number and replace it into table. If you move from this
>>record, unique type of index causes error event, so you shouldn't seek for
>>this random (but potentially non-unique) number. This way is better, especially
>>if you want to share table with another users (or using buffering)!.
>>
>>Peter
>
>Why is this better? I assume that you must change&restore the on error behavior to do this, isn't it?
>
>Vlad

This is better, if you use buffering in multiuser environment, because
another user can generate the same number as you if you have buffered
current record - it is "invisible" for him till you update your buffer.
Causing Error events in primary and unique indexes is especially
intended to cases like that.
I think, the best technique is buffer a record, generate number, try
to update record, if error event comes generate new number etc.
(Updating record causes error event in index without changing recordpointer).

Peter
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform