-2

I have to create a random cellnumber 07939393914 for automation testing purpose.

Last 079393(5 digits) digits should change randamly.. each time test runs..

Can any one suggest JAVA code for this ? or else Selenium Java code ?

Thanks

user2285608
  • 45
  • 3
  • 12

3 Answers3

2

Is this a number or a String? I ask as it has a leading zero. Take you initial number as 7939300000 then add to it Math.round(Math.Random()*10000)

If you want it as a String, take your string as "079393" and use Integer.toString on the result above, then concatentate them

user1111284
  • 886
  • 1
  • 6
  • 23
  • It's a phone number. So basically, a string. The leading `0` is important. – T.J. Crowder Jul 31 '13 at 09:27
  • Ah yes, sorry misread that. String it is – user1111284 Jul 31 '13 at 09:35
  • import java.util.Random; public class random{ public static void main(String args[]){ System.out.println("random number generation"); Random obj= new Random(); //create object for random class int rgen1= obj.nextInt(1000);//get random number with in the range of 0-1000 String cellnum = ("079393" + rgen1); System.out.println(cellnum); //if u want double random number use obj.nextDouble() } } – user2285608 Jul 31 '13 at 10:38
2

Use RandomStringUtils class.

String randomNumbers = RandomStringUtils.randomNumeric(5);
String phNo = 079393+randomNumbers;
Vinay
  • 648
  • 4
  • 12
0
var num=Math.ceil(Math.Random()*100000)

for random first 5 digit numbers and add var your_last_5digits; //as string to your last 5 digits

cellNumber='0'+num+your_last_5digits;
Lonely
  • 613
  • 3
  • 6
  • 14