I've been creating a random element generator of my first text adventure game, to be more specific, this:
Random Generation = new Random();
List<Integer> interact = new ArrayList<Integer>();
for (int generator = Generation.nextInt(5) + 3; generator > 0; generator--) {
interact.add(Generation.nextInt(3));
};
System.out.println(interact);`
Here, generator defines the amount of elements, and interact its a list that contains random numbers wich represent different interactive objects, the thing is, i need elements don't repeat, i've seen some previous questions, but i don't think they apply to my case, atleast completly.
I was thinking in a int a = Generation.nextInt(3); if (a != interact[]) {interact.add(a)} else {generator++};
but i dont know how to set an [any]
in comparing arrays.
Also, as an extra (not my main question, so if it isn't possible i don't care too much) Can you set wich elements can be repeated and wich not, in a single generator? Or maybe a better random one, for this specific case? Thanks for reading to here.
Aucun commentaire:
Enregistrer un commentaire