开发者

How to generate a random number

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 Val开发者_运维技巧ue


How to generate a random number

How to generate a random number


(source: wisc.edu)

  


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


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

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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜