Hey guys,
is there somone out there who knows how to randomly shUffle threw the variables stored in an array ?
Hey guys,
is there somone out there who knows how to randomly shUffle threw the variables stored in an array ?
TransistorHead:
Hey guys,is there somone out there who knows how to randomly shUffle threw the variables stored in an array ?
Hey! Yeah. So what you'll want to do is use a random number generator, and seed it so it won't be the same each time. You need to set up the code only to use numbers in the range of your array. Then, you can use those numbers to randomly address one of the index locations.
Use this: random() - Arduino Reference
Rough code idea:
Get random number + seed it
Make sure the number is in the range of the array
Use that number to find an array location
Hope it works out my friend!
-Englishscone
TransistorHead:
Hey guys,is there somone out there who knows how to randomly shUffle threw the variables stored in an array ?
Define "shuffle threw". Do you mean perform a fair shuffle (permutation) in-place? Do you mean enumerate the elements of an array in a random order without changing the stored order of an array?
Are repetitions allowed?
Technically arrays store values, not variables, arrays are themselves a kind of variable.
THere was This Code that I posted recently.
Mathematicians will notice that it's MUCH less random than a true "shuffle." Embedded programmers will appreciate that it uses very little data memory.