## Gl753

I'm working on assignment that requires me to generate and store 50 random PPS Numbers in an array but I'm not sure as to how to go about doing this. Keep in mind that I'm not asking anyone to do this assignment for me, this is just the part I need help with

## JamesCherrill 4,219

What's a "PPS number"?
The java.util.Random class has methods for generating random ints, arrays of random bytes etcetc

## Gl753

Personal Public Servive Number, It's a number that's 7 characters in lenght with a letter at the end e.g 000000E
I know how to generate a random number but I don't know how to generate one with a letter at the end

## JamesCherrill 4,219

If there's a letter in there then you cannot create it as a numeric type, it has to be a String. Generate the 7 digit number, convert it to String, add the letter on the end.
If that's an Irish PPS then there's a very clear description of how to generate the letter in the WikiPedia article

## Phaelax 52

I looked up PPS on wiki to see how it is calculated. Once the proper number is calculated, you can simply cast it to a char to match it up with an ASCII table.

``````        Random r = new Random();

StringBuilder sb = new StringBuilder(8);
int x = 0;
for(int i=0;i<7;i++){
int n = r.nextInt(10);
x = n * (8-i);
sb.append(n);
}
// Add 64 to the modulus result and cast
// to a char to convert the number to the
// corresponding letter in the ASCII table
sb.append((char)(x % 23 + 64));

System.out.println(sb);
``````

I believe this method would do the least amount of casting/conversion between numbers and strings. However, it does leave the potential for the following to be generated: 0000000@

## Janko_1

Hi Phaelax 52

I know this thread is old, but noticed a typo in your code -> pasting corrected one below ('x' should be incremented with each iteration by calculated value, not assigned a new value each time).

``````        Random r = new Random();
StringBuilder sb = new StringBuilder(8);
int x = 0;
for(int i=0;i<7;i++){
int n = r.nextInt(10);
x += n * (8-i);
sb.append(n);
}
// Add 64 to the modulus result and cast
// to a char to convert the number to the
// corresponding letter in the ASCII table
sb.append((char)(x % 23 + 64));
System.out.println(sb);``````