jeudi 19 mai 2016

Generate random binay String of fixed length in Java

I have the code below and all I want is to create a random binary string of fixed length (eg 4 bits).

public String Random(){
    Random rg = new Random();
    int n = rg.nextInt();
    return Integer.toBinaryString(n);   
}




Aucun commentaire:

Enregistrer un commentaire