1. ## random number

i have created two actions action1 and action2
in action one i have created on random number parameter with the name a, which is of type number and it random number parameter with numeric range from 0 to 100 and in the "Generate new random number" area i have selected 1st option-For each action iteration.

in expert view of action1 i type:
msgbox "action1"
msgbox(parameter("a"))

in expert view of action2 i type:
For i=1 to 5
msgbox(i)
RunAction "Action1", oneIteration, RandomNumber("arg_a")
Next

when i run it a msgbox is shown 6 times with value of a and i think in each iteration it should show a different value of 'a' but:
1st time a is different
2nd time a is different
3rd time a is different
4th time a is same as 3rd
5th time a is same as 3rd
6th time a is same as 3rd

can anybody please explain why it is not showing different value each time.

2. ## Re: random number

I am a bit confused:

1. Your loop will only iterate five times, not six.

2. Does Action2 really call back into Action1? What is the entry point Action here?

3. As a suggestion, use the Print utility to display your test values, then you won't have to interaction with MsgBox dialogs. This is not required by any means, just suggested.

4. I just ran the following simplied loop and the values are always random:
<font class="small">Code:</font><hr /><pre>
Option Explicit
'
Dim i
'
For i=1 to 5
print "i: "&amp;i&amp;", random num: "&amp;RandomNumber(1,100)
Next
</pre><hr />

5. I can't reproduce your steps: you say you create a random number parm in ACTION 1, but then you call ACTION 1 from ACTION 2, where the call to action 1 is passing a random number. So why are you then generating another random number in Action 1?

Perhaps you could simply your logic, gain confidence that RandomNumber work as it does for me in step 4 above, and then add complexity as needed in small steps?

-Hope this helps, Terry Horwath

3. ## Re: random number

terry thanks for answering my question. I would like to clear points 1 and 2 of urs.
firstly the msgbox will show 6 times when i click on run. firstly it will run for action1 and then next 5 times for action2.

yes action 2 is doing nothing but calling action1 in the line where it says runaction

4. ## Re: random number

I still can't visualize how this is working. So if you zip up the entire test script and attach it, I will run it and see what I spot.

-Terry

5. ## Re: random number

1)
open a new test

2)
in keyword view, right click on action1 and choose action properties and go to parametr tab and make a new parameter 'a' (number) with a default value of 0.

3)
again right click on action1 and choose action call properties, go to parameter tab and you will see 'a' in there, under the value heading make a single click, parameter button will appear on the right side when u click on it, it will open 'value configuration options' window. choose parameter radio button and choose 'random number' from that drop. let it be from 0 to 100. check the name checkbox and select the first option under 'Generate new random number'

click ok.

4)
now

in expert view of action1 i type:
msgbox "action1"
msgbox(parameter("a"))

5)
and make a new action action2 and in its expert view type:

For i=1 to 5
msgbox(i)
RunAction "Action1", oneIteration, RandomNumber("arg_a")
Next

6)
when i run it a msgbox is shown 6 times with value of a and i think in each iteration it should show a different value of 'a' but:
1st time a is different
2nd time a is different
3rd time a is different
4th time a is same as 3rd
5th time a is same as 3rd
6th time a is same as 3rd

6. ## Re: random number

Have you tried using a Randomize statement at the start of the script?

7. ## Re: random number

[ QUOTE ]
1)
open a new test
'
2)
in keyword view, right click on action1 and choose action properties and go to parametr tab and make a new parameter 'a' (number) with a default value of 0.
and make a new action action2 and in its expert view type:
...

[/ QUOTE ]
Why did'nt you just post your code as requested? Nothing proprietary in what you have described.

I am not going to try and follow your instructions to recreate test code you could simply ZIP up and post. If you can't do that, perhaps others have to the time to work with you. As Robbie points out above, you can work with random numbers without working with the RandomNumber object.

8. ## Re: random number

Hi Terry,

I don't know what u r asking, as I am not as pro in qtp as you. please tell which zip file u need.

9. ## Re: random number

Your QTP script which exhibits the problem. In its entirety, such that others can run it to see the failure.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.