# Java: Generating a random number of a certain length

Use the `Random.nextInt`

method as follows:

```
Random rnd = new Random();
int n = 100000 + rnd.nextInt(900000);
```

Since the upper bound given to `nextInt`

is exclusive, the resulting range is between 100000 and 999999.

## Related

Java: Generating a random String (password, booking reference, etc)

## Comments