1
public void click_random_retailer() 
{
 int randomNumber = new Random().nextInt(discoverPageObjects.merchantDivs.size() - 1) + 1;
 WebElement div = discoverPageObjects.merchantDivs.get(randomNumber);
 retailerName = div.findElement(By.cssSelector(discoverPageObjects.merchantNameLoc)).getText();
 System.out.println("Going to click Merchant -> " + retailerName);
 WebElement merchantBtn = div.findElement(By.cssSelector(discoverPageObjects.merchantBtnLoc));
 merchantBtn.click();
}
Bharat Mane
6,78512 gold badges42 silver badges69 bronze badges
asked May 24, 2017 at 12:56

1 Answer 1

1

No. From the Java documentation:

Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

As an aside, the range of the parameterless version of nextInt is Integer.MIN_VALUE to Integer.MAX_VALUE, inclusive.

Proof that it can return negative numbers:

$ cat r.java
import java.util.Random;
public class r {
 public static void main(final String[] args) {
 final Random random = new Random();
 for (int i=0; i<100; i++) {
 System.out.println(random.nextInt());
 }
 }
}
$ javac -d . r.java
$ java -cp . r | grep -- - | wc -l
49
answered May 24, 2017 at 13:35
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.