RandSeed Function

Action

Seeds the random number generator.

Syntax

RandSeed(iSeed)
Variable Description
iSeed The seed value for the random number generator. INTEGER.

Notes

  • RandSeed uses iSeed as a seed for the random values that all other random functions return.

  • 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))
    	[ ] 
    	[ ] // Every time Rand1 is executed it returns the same three numbers.
  • If you do not specify a seed value using RandSeed, random number functions will return different values for each run of a script during a testing session. For example, running test case Rand2 yields different results each time.
    [-] testcase Rand2() appstate none
    	[ ] // NO seed value specified
    	[ ] 
    	[ ] Print(RandReal())
    	[ ] Print(RandInt(1,12))
    	[ ] 
    	[ ] // First run:
    	[ ] // 0.363499
    	[ ] // 3
    	[ ] 
    	[ ] // Second run:
    	[ ] // 0.369257
    	[ ] // 11
    	[ ] 
    	[ ] // Third run:
    	[ ] // 0.067510
    	[ ] // 2
  • If you do not specify a seed value, the same series of results will occur in each testing session. For example, if you exit and restart Silk Test Classic and then run Rand2 for three consecutive times, you will get the same results as if you would have executed the test three times in the previous testing session.

  • If you want more randomized values in different testing sessions, set the seed value in a more random way. For example, base the argument to RandSeed on an unpredictable value from a database or on the current time. For example, the following statement sets a seed value based on the seconds component of the current time:
    RandSeed(GetDateTimePart(GetDateTime(), DTP_SECOND))
    Using this statement before you generate random numbers will yield different results when you run a series of tests in different testing sessions. For example:
    [-] testcase Rand3() appstate none
    	[ ] RandSeed(GetDateTimePart(GetDateTime(), DTP_SECOND))
    	[ ] Print(RandReal())
    	[ ] Print(RandInt(1,12))
    	[ ] 
    	[ ] // First run:
    	[ ] // 0.754183
    	[ ] // 6
    	[ ] 
    	[ ] // Second run:
    	[ ] // 0.756977
    	[ ] // 6
    	[ ] 
    	[ ] // Third run:
    	[ ] // 0.762099
    	[ ] // 9
    	[ ] 
    	[ ] // Quit Silk Test Classic, restart, then rerun test three times.
    	[ ] 
    	[ ] // First run after restarting:
    	[ ] // 0.754649
    	[ ] // 2
    	[ ] 
    	[ ] // Second run after restarting:
    	[ ] // 0.757908
    	[ ] // 10
    	[ ] 
    	[ ] // Third run after restarting:
    	[ ] // 0.760702
    	[ ] // 9