Thanks:  0
Likes:  0
Dislikes:  0

1. ## Random number problem

Hi All,
I am facing problem with Random number genaration.When ever i run the silk script it will create new Number for Version in my application.It is Unique value,i.e. if we run the script next time it should not create the existing number for the Version.
Actually i am using RandStr function to create number for Version.
But the thing is if we run the script more times there is a chance of creating existing number for Version.
So please let me know the better solution for this.
Regards,,,
RK

2. ## Re: Random number problem

Why do you use RandStr ?
do this :
take your last version (Ex: 10) and do + 1 (11).

OR
take the current date with the hour
05062005-092352.
That way you should be able to have unique run :-)

3. ## Re: Random number problem

tonylaq is right, use this and it will generate new number each time...
[ ] // This function returns a number in a string that represents the time and date
[ ] // to the second.
[+] string GetUniqueNumber ( )
[ ] string UniqueNumber = ""
[ ] int TempInt = 0
[ ] // Get datetime to second
[ ] TempInt = GetDateTimePart (GetDateTime(), DTP_MONTH)
[ ] UniqueNumber = UniqueNumber + Str(TempInt)
[ ] TempInt = GetDateTimePart (GetDateTime(), DTP_DAY)
[ ] UniqueNumber = UniqueNumber + Str(TempInt)
[ ] TempInt = GetDateTimePart (GetDateTime(), DTP_HOUR)
[ ] UniqueNumber = UniqueNumber + Str(TempInt)
[ ] TempInt = GetDateTimePart (GetDateTime(), DTP_MINUTE)
[ ] UniqueNumber = UniqueNumber + Str(TempInt)
[ ] TempInt = GetDateTimePart (GetDateTime(), DTP_SECOND)
[ ] UniqueNumber = UniqueNumber + Str(TempInt)
[ ]
[ ] return UniqueNumber

4. ## Re: Random number problem

I personally wasn't impressed with the pseudo randomness of anything but RandInt called after RandReal with a pseudo random seed (time based). This function seems to 'really be pseudo-random' to me. Inputs define output range for a pseudo random integer. I like intger outputs because they can be more readily applied to logic, etc.

</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">[ ]
[+] INTEGER getRandInt(INTEGER startInt, INTEGER endInt)
[ ] INTEGER outInt
[ ]
[ ] RandSeed (GetDateTimePart (GetDateTime (), DTP_SECOND))
[ ] RandReal()
[ ] outInt = RandInt(startInt,endInt)
[ ] return outInt</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">This, of couse, is for making a random choice and not creating a random string. To get a guaranteed unique random string, I'd try to use the windows GUID generation calls, if possible.

5. ## Re: Random number problem

Why don't you use milliseconds GetDateTime () and then convert it to milliseconds ... You don't need random number [img]images/icons/wink.gif[/img] .

6. ## Re: Random number problem

Good question. I can't really remember, but I think it is because I wanted the 'normalized randomness' of RandInt so that I could write code to randomly pick one out of ten testcases, for instance. RandInt() does the normalization for you provided that you call RandSeed with a (not normalized) random number first. Without adding in the seemingly unnecessary RandReal() call, though, it never was very random in practice. My guess is that RandReal actually uses the seed and RandInt may not.

Really, the best solution for RAVIKUMAR is probably to just use names like a.txt, a2.txt, a3.txt, etc.

Example:
</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"> [-] if (SYS_FileExists (&quot;a.txt&quot)
[-] for (index=2; index &lt; 9; index++)
[ ] STRING temp = &quot;a&quot;
[ ] temp += [STRING]index
[ ] temp += &quot;.txt&quot;
[-] if (SYS_FileExists (temp))
[ ] continue
[-] else
[ ] break</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">

[ 04-07-2005, 01:56 PM: Message edited by: Chris Mead ]

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.