How to generate a random number

2019-06-27 03:24发布

问题:

I have to create a test for homework using Selenium IDE and create a scenario to generate a random number. I'm struggling with what I need to type and what field to type in.

What should I type in?: Command Target Value

回答1:



回答2:

i always use this to create random username and e-mails

storeEval > Math.round (Math.random() * 1357) > random
type > id=UserName > selenium${random}

and

storeEval > Math.round (Math.random() * 1357) > random
type > id=UserEmail > selenium${random}@am.com

i hope they can help you



回答3:

I use this often in my JUnit tests to create random inputs values.

int randNum = (int) (Math.random() * MAXVALUE);


回答4:

This is what I use:

Random rand = new Random(System.currentTimeMillis());
int num = rand.nextInt(range);

Range is the max number you want to return. Num will be something between 0 and range.



回答5:

you can use

Random rndNum = new Random();    System.out.println("Num "+rndNum.nextInt());

for a single number like: Num -1597641332

or try

Random rndNum= new Random();    int rndNum1 = 0;

   for (int nbr = 1; nbr <= 3; nbr++) {
       rndNum1 = rndNum.nextInt();
       System.out.println("Number: " + rndNum1);    }

for multiple number of random numbers like

Number: -1891834125 Number: -1541629941 Number: -129634738