We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi there, i have been searching for a big part of the day for a Solution to my problem. I have an Array(10 places) i would like to fill it with int's all random from 1 till 10.. but they cant be the same.
at 1 point i was thinking about using randomSeed put that in a variable use % modulo on it.
if it's even put 2 in array place 1. if its again even add 2 to the previous value and put that in array place 2.
Same goes for uneven.
But is this a good solution. Help me out plz, Thnx
Answers
You can try IntList structure out.
When picking a random() value, check out whether that's already stored using hasValue() method!
If positive, re-pick another value! Use a
do...while
loop block for it. :-jNot sure if I fully understand you but this will create a 10 element array with the values 1-10 (non-repeating) in random positions
Well, here's my mentioned solution: :-??
An even simpler solution is fill up the IntList w/ a continuous range from 1 to RANGE.
Only then, apply shuffle() method to get random positions outta it! B-)
And after it, you'd prefer a regular Array, use array() method to obtain it outta the IntList! :bz
I will try them both out, thanks allot
hi guys,
A few days ago you helped me on this topic: Processing 2.0 Random without duplicate as interger is it possible?
you send in your code to shuffle values in an array. could you help me implement it in this.
greetings,
Ben
My solutions above involved an IntList rather than a regular Array.
Only after shuffling, an Array is created outta it!
Quarks' solution used Array exclusively. However, both of ours were 1D, not 2D! :-SS
Thus, more thought is needed and I don't have time for it now! X_X
This topic is now closed and can be continued here