Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / shuffle cards

Author
Message
Nokiaqd
14
Years of Service
User Offline
Joined: 31st Aug 2009
Location:
Posted: 25th Aug 2011 11:33 Edited at: 25th Aug 2011 11:34
who can help implement mixing in an array of numbers. I have 15 numbers and they need to take 15 but not in order.

I tried using a random function but sometimes it happens that the numbers are repeated.

Sorry for my English.
Thank you in advance for your answers \ suggestions.!!
Daniel TGC
Retired Moderator
17
Years of Service
User Offline
Joined: 19th Feb 2007
Location: TGC
Posted: 25th Aug 2011 14:09
SetRandomSeed(timer()) place that command in your menu code, and have it trigger when you tap the screen. timer() works by keep track of the amount of time that has elapsed since the application started, by having the user tap the screen this adds an unpredictable element that seeds the random number generator with a new random number.
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 25th Aug 2011 16:50
You can actuallly "shuffle" the array.

Pick two random elements. Swap the values. Repeat 100 times.

Your array is shuffled!

Here's some AppGameKit code...



Nokiaqd
14
Years of Service
User Offline
Joined: 31st Aug 2009
Location:
Posted: 25th Aug 2011 17:56
Rich Dersheimer

thank you for the example is what I was looking for.
Nickydude
Retired Moderator
17
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Look outside...
Posted: 26th Aug 2011 01:18
Rich Dersheimer, could i add this to the guide?

I reject your reality and substitute my own...
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 26th Aug 2011 01:50
@Nickydude - of course!

Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 26th Aug 2011 02:08 Edited at: 26th Aug 2011 02:13
What prevents the random numbers from being the same, and thus swapping itself?
How many times out of the hundred do you think it would happen?



What if the 100 times was random in a range of 100 to 200?

Nickydude
Retired Moderator
17
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Look outside...
Posted: 26th Aug 2011 02:20
The way I would do it (but I'm not sure of the coding or whether it's most proficient) would be:

1/. Create an array
2/. Create a duplicate array
3/. Shuffle from the first array and put in second
4/. Pick a random array field from second
5/. Check whether that field holds a number that's not being used (say 999)
6/. If it doesn't, do whatever you going to do with it then put 999 in it.
7/. Goto 4 unless it contains 999
8/. If that particular field that was randomly chosen contains 999, choose another (goto 4).

Does that make sense?

I reject your reality and substitute my own...
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 26th Aug 2011 03:24
Quote: "What prevents the random numbers from being the same, and thus swapping itself?"


Although the odds are against it, it would be entirely possible to run the loop 10,000 times, and end up with the values in the same order they started in. That would qualify as a random result as well.

Login to post a reply

Server time is: 2024-03-29 13:33:30
Your offset time is: 2024-03-29 13:33:30