Random Character within Range without repetation in java





/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package random;

import java.util.*;

public class DemoRandom
{
    public static void main(String[] args)
    {
        Random r=new Random();
        int i;
        ArrayList<Integer> arr=new ArrayList<Integer>();
        for(i=65;i<=90;i++)
        {
            arr.add(i);
        }  
        int cnt=arr.size();
        for(i=0;i<cnt;i++)
        {
         
            int z=r.nextInt(arr.size());
            System.out.println(Character.toChars(arr.get(z)));
            arr.remove(z);
        }
        System.out.print(cnt+"");
    }
}


OUTPUT 
S
L
H
U
X
G
E
C
R
F
V
K
Z
Q
M
A
Y
P
T
W
D
B
I
J
O
N
Total : 26
Random Character within Range without repetation in java Random Character within Range without repetation in java Reviewed by Unknown on 11:59 am Rating: 5

1 comment: