How to generate random number through scripts.

289 views
Skip to first unread message

Amit

unread,
Feb 12, 2012, 1:40:28 PM2/12/12
to Selenium Users
Hi,

I want to generate a new email id each time for registering around
1000 users, need to know how can I do this in webwriver using random
number function (if any).


Thanks,
Amit

bs

unread,
Feb 13, 2012, 3:42:28 AM2/13/12
to Selenium Users
This is Java function and is independent of selenium.

Random rg = new Random();
for (int idx = 1; idx <= 1000; ++idx){
int randomInt = rg.nextInt(1000);
System.out.println("Generated : " + randomInt);
}

santosh h s

unread,
Feb 13, 2012, 1:27:41 PM2/13/12
to seleniu...@googlegroups.com
I have written random generator in python


class Random:

    def randInt(self, nLowerbound, nUpperbound):
        """
        generates random integer lower bound and upper bound needs to be passed
        """
        return int((nUpperbound - nLowerbound + 1) * random.random() + nLowerbound)

    def randStr(self, nStringLength, isUpperCase):
        """
        generates random strings length of the string and is Uppercase boolean flag needs to passed needs to be passed
        """
        randmStr = ''
        for item in range(nStringLength):
            if isUpperCase == True:
                nInt = self.randInt(65, 70) #Uppercase letter from 'A' to 'F'
            else:
                nInt = self.randInt(97, 102) #Lowercase letter from 'a' to 'f'
            randmStr = randmStr + chr(nInt)
        return randmStr

    def randIntStr(self, nStringLength):
        """
        generates random alpha numeric characters length of the string needs to passed needs to be passed
        """
        randmalpha_num = ''
        for item in range(nStringLength):
            temp = self.randInt(1, 2)
            if temp == 1:
                nInt = self.randInt(48, 57) #Digit 0 to 9
            else:
                nInt = self.randInt(65, 71) #Uppercase letter from 'A' to 'F'
            randmalpha_num = randmalpha_num + chr(nInt)
        return randmalpha_num

    def randNumerical(self, nStringLength):
        """
        generates random  numeric characters length of the string needs to passed needs to be passed
        """
        rand_num=""
        for item in range(nStringLength):
            nInt = self.randInt(48, 57) #Digit 0 to 9
            rand_num = rand_num + str(nInt)
            if len(rand_num)==32:
                break;
        return rand_num














}

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.




--

/Santosh
Reply all
Reply to author
Forward
0 new messages