Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
RAND() not very random
Message
From
21/09/2006 07:39:31
 
 
To
21/09/2006 07:19:59
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01155607
Message ID:
01155887
Views:
18
>>>>Here's a funny one. No biggie but a bit annoying.
>>>>
>>>>I use the following code to generate a fairly unique filename for my exported XLS file, incorporating today's date + a random no. suffix, in case several XLSs are generated in one session/day, so they don't need to keep typing in a new name. This has been working fine till today. But today it keeps giving 851 and 856 (and others similar) off my m/c AND the 2 users' m/cs, such that my code, and Excel's interface keep asking if want overwrite.
>>>>
>>>>
>>>>lcRandNum	  = ALLTRIM( STR( INT( RAND() * 1000)))
>>>>lcDateStr	  = ALLTRIM( DTOC( DATE()))
>>>>lcDateStr	  = STRTRAN( lcDateStr, "-", "_") + lcRandNum
>>>>lcFilePath = PUTFILE("Export Results", "S" + lcDateStr, "XLS")
>>>>
>>>>
>>>>Both when testing and today I've been issuing:
>>>>
>>>>? STR( INT( RAND() * 1000))
>>>>
>>>>repeatedly at the command line with expected varied results. Any ideas?
>>>>
>>>>'ppreciate it
>>>>
>>>>Terry
>>>
>>>uses RAND() for this task is wrong.
>>
>>How so, amd why not suggest an alternative? It's just a cheap & cheerful way of generating a (fairly) unigue file name.
>
>RAND() is not an unique generator.
>
>every sequential generator is a solution.
>
>this is a partial solution:
>
>#define TIMENAME   '_'+DTOS(DATE())+' '+CHRTRAN(TIME(1),':.','$$')
>
That's one solution - back-to-front date, not very recognisable, etc.

:-)
- Whoever said that women are the weaker sex never tried to wrest the bedclothes off one in the middle of the night
- Worry is the interest you pay, in advance, for a loan that you may never need to take out.
Previous
Reply
Map
View

Click here to load this message in the networking platform