@jeremydouglass
Oh sorry,to not answer you. Now I got a answer.
"But how can I take those numbers to separate for use with others."
that sentence ,I mean
IntList il = IntList.fromRange(1, 11);
il.shuffle(this);
il.resize(5);
println(il);
exit();
If I use that code, How can I separate them to be unique number as such as
B[1] , B[2] , B[3]
and B[1] = shuffle first number.
B[2] = shuffle second number.
B[3] = shuffle third number.
and any number.
for use with others function.
I 'm so sorry from my english ,if u don't understand.
and this is my code that I got a answer.
import java.util.Random;
int[] number = new int[5];
int count=0;
int num;
Random r = new Random();
while(count<number.length){
num = r.nextInt(10);
boolean repeat = false;
do{ //1
for(int i=0; i<number.length; i++){ //2
if(num == number[i]){//3
repeat = true;
break;
} //3
else if(i == count){
number[count] = num;
count++;
repeat = true;
break;
}
} //2
}while(!repeat); //1
}
for(int j = 0; j < number.length; j++){
System.out.print(number[j]+" ");
}
Answers
Fill an array with those
Shuffle the array
Display the first number, then the 2nd number etc. from this array
I don't know how to type that syntax and If I need 5 numbers. How I should type ?
@alohaman.
I need to do something with a list of Integers.
...only in a random order. "Shuffled."
Start by using that example sketch right there in the reference.
This is what to do if you are working with a list (like a deck of cards, with each card occurring once.
If instead you were trying to but instead like rolling a 10-sided die (and each value is independent)
...then you can do that like this:
use
(int)random(1, 11)
to get integers from 1 to 10Thanks everyone attend my post
I use shuffle and list of integers. It can work to random 5 numbers. But how can I take those numbers to separate for use with others.
I don't understand this sentence.
Can you show your code, and explain exactly what you are trying to do?
Is your problem this?:
Q. "I made an IntList. How do I get a number from the IntList?"
A. "Read the
IntList
reference! It shows an example."The entry has an example sketch that shows how to use
IntList.get()
, copy the value into anint
, then draw it as text.@jeremydouglass Oh sorry,to not answer you. Now I got a answer. "But how can I take those numbers to separate for use with others." that sentence ,I mean
If I use that code, How can I separate them to be unique number as such as B[1] , B[2] , B[3] and B[1] = shuffle first number. B[2] = shuffle second number. B[3] = shuffle third number. and any number. for use with others function. I 'm so sorry from my english ,if u don't understand.
and this is my code that I got a answer.
Credit : https://stackoverflow.com/questions/33636887/generating-10-random-numbers-without-duplicate-with-fundamental-techniques
@alohaman --
Read the IntList reference!
Read the IntList reference!
https://processing.org/reference/IntList.html
The example at the top shows how to get a specific number -- using get()!
The entry on get() right below says "get(): Get an entry at a particular index"
Read the IntList reference!
@jeremydouglass hah, I got it. Thanks for repeat that for me.