10-13-2022, 04:42 AM
(This post was last modified: 10-13-2022, 04:43 AM by PhilOfPerth.)
(10-13-2022, 04:24 AM)mnrvovrfc Wrote:But does it matter if they are the same value? Obviously, there would not be a swap, but other swaps wouldn't be affected, and if there were only a small number of elements, the whole swap sequence could be looped a few times to ensure thorough mixing.Quote:You beat me (again)!
I'm in the middle (or at least I've started) writing a game based on a similar algorithm.
I use this for shuffling:
for a=1 to 52
swop=int (rnd*52)+1
swap deck$(a),deck$(swop)
next
When I look at something like this, my urge is to prevent "a" and "swop" from having the same value, if they're both integers. Such as:
Code: (Select All)for a=1 to 52
do
swop=int (rnd*52)+1
loop while swop=a
swap deck$(a),deck$(swop)
next
Otherwise could leave out the "do" and straight out test the two integers and, if not equal, actually do the swap.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.)