Unanswered question

Generating a random number between 2 and variable ?

Hi guys,

I would like to generate a random number between 2 and the number of page available for my list page.
I am able to extract the number of page available and it has been extracted in a variable.

So I would like an integer between 2 and ${maxNumberPage}.

How can I do that ?
Thanks,
Alex

Alexandre M.
Alexandre M.

Alexandre M.

Level
0
1 / 100
point

Answers

christophe M.
christophe M.

christophe M.

Level
4
5000 / 5000
points
Team

NeoLoad doesn't provide this out-of-the-box, you need to write a piece of Javascript.

Overview of Javascript:

1. Get the value of the Upper bound
2. Generate the random number
3. Set a variable with the random number.

So, use a "JavaScript" action and use a script like:

"var maxPage = context.variableManager.getValue("maxNumberPage");
if (maxPage == null) { context.fail("Variable 'maxNumberPage' not found"); }

var minPage = 2;

// random with min and max included:
var randomPage = Math.floor((Math.random() * (maxPage - minPage + 1)) + minPage );

context.variableManager.setValue("MyRandomPage",randomPage); "