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 / Random Number

Author
Message
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 14th May 2016 18:34
Hi.

I want generate random number between (1,6) with repeat number and wrote this code but it don't work.

please guide me.

Thanks.

Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 14th May 2016 19:37
No, that doesn't work.

You should go through the numbers 1-6 and put them into a random position in the array. You start with a random position and then use a while loop to step through each position in the array until you find one with the value 0. That's the position you add the number into. I leave it to you to figure out the code for yourself. It's a good learning experience.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 15th May 2016 05:44 Edited at: 15th May 2016 05:50
Thanks Digital Awakening

if possible you learn it to me. because currently I working on Big project and really really My mind is tired and I do not focus. but I hope learn new experience.

if possible.

Thanks.
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 15th May 2016 08:23
I do not recommend that you work on a big project before completing smaller projects. Also, being a programmer means that you must always solve problems. If you do not practice solving problems, you will not improve and grow as a programmer.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 15th May 2016 08:29
I wrote it.



but there is easiest way?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 15th May 2016 09:49
you can fill also the array fom 1 to 6 , in for loop make 2 random index from1-6 and exchange (swap) the numbers in this array.
similar you have cards in your hand and change the positions.

AGK (Steam) V2.0.18 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 15th May 2016 09:50 Edited at: 15th May 2016 09:52
Behdadsoft:
That's a good try. But you should avoid using GOTO. There's a loop called WHILE that you can use instead of FOR.

http://www.appgamekit.com/documentation/language/16_while.htm
Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 15th May 2016 09:52
Markus idea works, but I think it's too complex for such a simple task. If you need to shuffle a deck of cards then it's great.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 15th May 2016 09:52
i found my example in other thread:
AGK (Steam) V2.0.18 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 15th May 2016 11:27 Edited at: 15th May 2016 12:04
Quote: "Behdadsoft:
That's a good try. But you should avoid using GOTO. There's a loop called WHILE that you can use instead of FOR."


Thanks, but I don't know how can write it with While. Really I confused

also Thanks Markus for your help.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 16th May 2016 09:19
Quote: "goto start"

Wow! Avoid this like the plague!
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 23rd May 2016 01:25 Edited at: 23rd May 2016 01:25
I guess this post is to shuffle a pack in an array so a number is not repeated?

I would put the numbers in the array first and then just shuffle the order.




@Behdadsoft, is this what you mean?

Quote: "with repeat number"


Just that you put WITH repeat or is that meant to be WITHOUT?
The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 23rd May 2016 10:30
Quote: "@Behdadsoft, is this what you mean?"


sorry, I mean without repeat number.
tboy
11
Years of Service
User Offline
Joined: 1st Jan 2013
Location: UK
Posted: 23rd May 2016 15:55
I find using a Durstenfeld shuffle which is based on the Fish-Yates algorithm
quite a nice method for shuffling.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 23rd May 2016 16:24 Edited at: 23rd May 2016 16:27
Quote: "Quote: "goto start"

Wow! Avoid this like the plague!"
- Especially from INSIDE a for loop! TBH I'm surprised you didn't cause Total Protonic Reversal (all life as you know it stopping instantaneously and every molecule in your body exploding at the speed of light), either that or the creation of a black hole that destroys the entire solar system. It's almost as bad as Googling Google! Are you mental? Haha!

Quote: "I find using a Durstenfeld shuffle which is based on the Fish-Yates algorithm
quite a nice method for shuffling."
Lol!!

Show me teh codez!
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
SpecTre
Developer
21
Years of Service
User Offline
Joined: 24th Feb 2003
Location: UK
Posted: 23rd May 2016 20:54
@Behdadsoft, yep well use that snippet as it doesn't repeat and doesn't have a goto and is nice and simple.
The Amiga and Amos were great!
My website LEAP - Download Paint Pot here!
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 17th Jun 2016 23:26
Thanks SpecTre for your code.

Login to post a reply

Server time is: 2024-04-19 12:25:17
Your offset time is: 2024-04-19 12:25:17