Quote:
I have a code written below to control 8 relays in random.
Random means anything between 0 and 8 relays.
To get 3 relays in 8, you should use a technique named
shuffle.
shuffling
You must build a program that will simulate shuffling cards.
Say that you have a deck of 8 cards, 5 cards black and 3 cards red.
You pick 1 at random in the 8 cards, and you remove it from the deck.
You pick 1 at random in the 7 cards remaining, and you remove it from the deck.
And so on ...
How does it work in a program ?
Set an array of size 8, set 5 elements to 0 and 3 elements to 1.
Pick a random number between 1 and 8, swap that element with element 1.
Pick a random number between 2 and 8, swap that element with element 2.
Pick a random number between 3 and 8, swap that element with element 3.
...
The result in the array is the position of your relays.