Thanks:  0
Likes:  0
Dislikes:  0

# Thread: RandInt - not so random, seed dos not randomize

1. ## RandInt - not so random, seed dos not randomize

Hi, I'm trying to generate random integers on SilkTest 8.0. (The ultimate problem is to get random selection of items under the tree control, so, I am recursively traversing a tree, selecting a random number of children at each level to either expand further or select. Should be pretty common task).

However, using RandInt is not random enough, the output values seem to be clustered (middle values in the range seem to be picked more often than boundary).
Ex. selecting random numbers btwn 1 and 4, mostly restuls on average, in 2's and 3s, 1 and 4 are quite rare.
Seeding random generator with seconds value of time, makes it even worse:
RandInt (1,2) always gives 1. (That is IF I seed). If I don't, it returns 1 or 2.

Note: I do not have a fix for RandInt (for SilkTest 8.0) because I have an evaluation copy. But I am aware that it does not respect max value. Or is the problem not only with the max value but with the whole function???

2. ## Re: RandInt - not so random, seed dos not randomize

I believe the problems are with random functions in general. I had problems with RandPick which I tried to correct by using RandInt to generate my value to pick. I then had to wrap it all up in a while loop to ensure I never went beyond the upper limit. I eventually rolled back to version 7.6 due to this problem as well as some other issues.
As for RandSeed function, the way I understand it is that it actually makes random functions less random. Per the help file:
For a given seed value, RandSeed will generate a reproducible series of random values. For example, the following code will always generate the same values, because the starting seed value is always the same.

testcase Rand1 () appstate none
INTEGER iSeed = 10 // a random number generation seed
RandSeed (iSeed)
Print (RandInt (0, 100))
Print (RandInt (0, 100))
Print (RandInt (0, 100))

// Results:
// Get the following every time Rand1 is run:
// 75
// 79
// 3

3. ## Re: RandInt - not so random, seed dos not randomize

FYI, I just saw there is a hotfix on the Segue site to fix the random generation problems. Of course since I rolled back I have no intention of seeing if it actually works now. [img]images/icons/smile.gif[/img]

4. ## Re: RandInt - not so random, seed dos not randomize

I faced similar kind of thing but fortunately the random value I needed was of around 16 characters....So I generated random values part wise say, 4 calls to generate random values between 1-4 characters then I joined them like
randval1 + randval2 + randval3 + randval4...All are string here and then I converted them to integer which was of around 16 digits and random also...The seed value was the second value of time and also in each call I altered it...

5. ## Re: RandInt - not so random, seed dos not randomize

I think (as per help files) seed function generates reproducable (each time) series of numbers IFF the parameter is the same. Which makes sense.
However, if the seed value is different every time, theoretically, the sequences should be also different every time. That's why time value in seconds is used for randomization.

And fix - yes I know, but as I've said, we're still evaluating, and 14 days are over, so I can't get it [img]images/icons/smile.gif[/img] But for now I just check for max.

At this point I got function to work pretty well, however, the problem of clustering of values in the middle of the range still remains.

I guess, eventually, I'll just use some external randomizing function.

#### 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.