SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 7 of 7
  1. #1
    Moderator
    Join Date
    Sep 2001
    Location
    Doncaster, UK
    Posts
    5,788
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Issue with RandomNumber in QTP 10

    Open a new test
    Add this line to the test
    MsgBox RandomNumber(1000,9999)
    Save test
    CLOSE QTP - This is important
    Reopen test
    Run the line of code 4 times

    You will see the following sequence of numbers

    1010
    3120
    6833
    1669

    And if you close and reopen QTP and rerun the test you will get the same sequence.

    Mark Smith.

  2. #2
    Junior Member
    Join Date
    Jun 2006
    Location
    Columbia MD USA
    Posts
    14
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Issue with RandomNumber in QTP 10

    Semi-Random Numbers anyone?
    So what happens with diffrent ranges?
    I'm going to check out 100,999
    Scotty_p

  3. #3
    Member
    Join Date
    Oct 2003
    Location
    New Zealand
    Posts
    97
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Issue with RandomNumber in QTP 10

    I am not sure about QTP, but most of the languages behave in the same way - giving the same set of random number sequence. Random numbers are generated using a algorithm by giving an initial value called seed. As far as the seed is the same, number sequence is always the same. This makes it easier during development and debugging.

    To make it really random, usually you have to include another call before that, something like 'Randomize' - it makes it to change the seed of the random number generator hence giving different sequences every time. May be you should look for a similar command in QTP.

    Krish

  4. #4
    SQA Knight
    Join Date
    Jul 1999
    Location
    Grand Rapids, MI
    Posts
    3,727
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Issue with RandomNumber in QTP 10

    This thread provides some "seed" code that should ensure random numbers in Mark's code above:

    http://www.sqaforums.com/showthreade...age=0&vc=1

    I also think I saw Tarun use a date/time stamp of "now" to generate a seed, but in that case you would not be able to reproduce the "random walk".

    -Hope this helps, Terry

  5. #5
    Member
    Join Date
    Apr 2007
    Posts
    197
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Issue with RandomNumber in QTP 10

    just run ' Randomize ' before you use the rand func. you will not see that repetative numbers again

    syntax:

    randomize


    ~Neethu

  6. #6
    Moderator
    Join Date
    Sep 2001
    Location
    Doncaster, UK
    Posts
    5,788
    Post Thanks / Like
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Issue with RandomNumber in QTP 10

    [ QUOTE ]
    just run ' Randomize ' before you use the rand func. you will not see that repetative numbers again


    [/ QUOTE ]

    The point is that this is a QTP in-built function and you should not have to use Randomize, and I'm informed that it worked OK in 9.2

    Mark Smith.

  7. #7
    SQA Knight
    Join Date
    Jul 1999
    Location
    Grand Rapids, MI
    Posts
    3,727
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Issue with RandomNumber in QTP 10

    [ QUOTE ]
    The point is that this is a QTP in-built function and you should not have to use Randomize, and I'm informed that it worked OK in 9.2

    [/ QUOTE ]

    I have had to use the randomize code snippet I provided above since version 8.2. And this is an issue with the built-in vbScript engine. Here are the comments from randomize() help:

    ...
    If Randomize is not used, the Rnd function (with no arguments) uses the same number as a seed the first time it is called, and thereafter uses the last generated number as a seed value.
    ...

    So the "first time" part of this sentance refers to the behavior after QTP is restarted, hence the repeating of the numbers in the first post in this thread.

 

 

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.
Resources saved on this page: MySQL 10.71%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 08:07 PM.

Copyright BetaSoft Inc.