I'm trying to generate meaningless words without using any Random() functions. I figured out that i can use current clock or mouse coordinate. And i picked to use current clock. Here is the code i wrote.
private final char[] charray = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
private char getRandomCharacter(){
return charray[random(charray.length)];
}
private int random(int value){
value =(int) System.nanoTime()% 52;
return value;
}
protected Randomizer(){
boolean running = true;
int count = 0;
int max = 5;
while(running){
StringBuilder sb = new StringBuilder();
int size = random(25) + random(25);
for (int i = 0; i < size; i++) {
sb.append(getRandomCharacter());
}
System.out.println("Random Line : " + sb.toString());
if (count++ == max) {
running = false;
System.out.println("All of them are random.");
}
}
}
public static void main(String[] args) {
new Randomizer();
}
I was expecting the out put like : axdlMkjiIfjcmqQopv etc.. but i get something like this : ZNNrrrUUUUxxxxbbbhhhLLLLoooRRRRRvvvYYYYBBBBfffI or JmmmPPKKKKnnnnRRBeeHHHHlllllOOOOrrrVVVVV Why there are too much continious. Is nanoTime too slow for that or what?I used currentTimeMillis before that and it was much worser. I couldn't figured out and couldn't find any source about how to random with current clock. PS: I'm newbie pls dont kill me.
Aucun commentaire:
Enregistrer un commentaire