Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to Make RAND() issue UNIQUE numbers?
Message
 
À
04/12/1997 20:20:07
Edward Crawford
City Facilities Management
Glasgow, Royaume Uni
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00063913
Message ID:
00063936
Vues:
68
>>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?
>
>In addition to check to be sure that the number is indeed unique, has Vlad has said, you might also want to call RAND(-1). This will use the system clock as the seed. I have found that you are far less likely to get a repeat.
>-Ed

However, if you are doing a series of these programmatically, you may have a problem with the system clock not updating fast enough. Note in the Help it says to issue Rand() with a negative number first, then Rand() with no parameter.

HTH
Barbara
Barbara Paltiel, Paltiel Inc.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform