Hallo, ich schreibe einen random Keygenerator, der jedes Zeichen einmal verwenden soll. Leider funktioniert er nicht. Vielleicht weiß ja jemand warum.
Java
package com.example.writesave;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import java.util.Random;
public class NewKey extends AppCompatActivity {
private Button bntSave;
private TextView yourKey;
private String[] allKeys = {"°", "!","§","$","%","&","/","(",")","=","?","@","€","*","+","~","'","#","<",">","|",";",",",":",".","_","-","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","ß","1","2","3","4","5","6","7","8","9","0"};
private String[] key;
private String set;
private String[] used={"´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´","´"};
private boolean go;
private boolean isKeyFree;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_key);
getSupportActionBar().hide();
key = new String[64];
go = false;
isKeyFree = true;
Random random= new Random();
for(int i = 0; i <= allKeys.length; i++){
while (go == false){
int thisKey = random.nextInt(allKeys.length);
isKeyFree = true;
for(int j=0;j<=used.length;j++){
if(allKeys[thisKey] == used[j]){
isKeyFree = false;
break;
}
}
if (isKeyFree = true){
used[i] = allKeys[thisKey];
set = set + allKeys[thisKey];
go = true;
}
}
}
yourKey.setText(set);
}
}
Alles anzeigen