Shuffle array

Get help using Construct 2

Post » Sun Mar 24, 2013 2:02 pm

Guys I need a help .

I have array .

example

1, 2,3,4,5,6,7,8,9,


now i need a shuffle the numbers.

when i use random operator . i have shuffled numbers but there are repeted ..

i need what numbers don;t repeated like 3,6,4,9,1,7,5,8,2
B
13
S
3
G
3
Posts: 28
Reputation: 2,798

Post » Sun Mar 24, 2013 5:59 pm

This topic covers shuffling cards but it is applicable:
http://www.scirra.com/forum/randomized-an-array-for-a-deck-of-cards_topic45833.htmlR0J0hound2013-03-24 17:59:33
B
79
S
24
G
54
Posts: 4,738
Reputation: 40,739

Post » Mon Mar 25, 2013 11:57 am

@r0j0hound

I have read this topic .. but resolve problem whit plugin Randomized Array
http://www.scirra.com/forum/plugin-randomarray_topic45277.html

10x for answering:) Asatur2013-03-25 11:59:25
B
13
S
3
G
3
Posts: 28
Reputation: 2,798

Post » Mon Mar 25, 2013 12:35 pm

I wrote a tutorial about this topic
https://www.scirra.com/tutorials/469/implementing-fisher-yates-shuffling-algorithm
B
20
S
8
G
6
Posts: 176
Reputation: 8,047

Post » Mon Mar 25, 2013 5:27 pm

[QUOTE=mrcgkh] I wrote a tutorial about this topic
https://www.scirra.com/tutorials/469/implementing-fisher-yates-shuffling-algorithm[/QUOTE]

10x a lot of .. I understand :)
B
13
S
3
G
3
Posts: 28
Reputation: 2,798

Post » Mon Mar 25, 2013 9:32 pm

Another great tutorial that may help you:

https://www.scirra.com/tutorials/315/generating-random-numbers-without-duplicatesjegcelorio2013-03-25 21:33:02
B
17
S
4
G
3
Posts: 73
Reputation: 3,723

Post » Mon Mar 25, 2013 9:37 pm

Also have a look at my solution that I used

http://www.scirra.com/forum/generate-unique-times-tables-questions-array_topic65058.html?KW=

It doesn't do the shuffle but it would be pretty easy to implement.

Just loop through the array use a temp variable to hold a value so you can swap two array elements.czar2013-03-25 21:38:02
B
31
S
8
G
5
Posts: 436
Reputation: 5,836

Post » Tue Mar 26, 2013 6:10 am

kittiewan's solution theoretically can takes forever. Fisher Yates is a O(n) solution. So it guarantees a maximum n times loop.
B
20
S
8
G
6
Posts: 176
Reputation: 8,047


Return to How do I....?

Who is online

Users browsing this forum: Artpunk, Axiomaltd, MACPK, nicklowkcmagic, OddConfection, radbrothers and 25 guests