How to generate a random number

一世执手 提交于 2019-12-10 17:33:25

问题


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:



(source: wisc.edu)

  




回答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



来源:https://stackoverflow.com/questions/2831088/how-to-generate-a-random-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!