Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Catching repeat numbers
#11
EDIT::::I added comments to the original post that may make more sense than this post. Review the original code...it may be more clear now. Ciao.

Quote:Wow, thanks.... yeah so i understand what your saying. i dont get two parts

LOOP UNTIL (shuffledenough > 100)

i know that is loop untill the value of shuffledenough is greater thatn 100. but why?

shuffledenough increments after each swap. you have to have some condition that says, "enough already...I'm shuffled". What that condition is is up to you. I chose 100 arbitrarily...with my code, how many "shuffles" you need will depend on how many variabls are in your array. However, there are ways to make this non-hard coded. for example, you could make it so that after shuffledenough > 10 * arraysize, then enough is enough...



Quote:LOOP WHILE (x = y)
SWAP array(x), array(y)

i dont full get what swap does. and how does array(x) and array(y) get a value in for the numbers in the array?

x and y are two *different* values that fall within the array index. They are *different* because we kept selecting random x and y values until we got two that didn't match (loop while (x=y) ensures that x and y are not equal *outside* the loop). (which most likely happened on the first try *if* your deck contained more than 2 cards ;- ) As such, array(x) represents the value at array position x, and array(y) represents the value at array position y. swap array(x), array(y) simply swaps these values. after the swap, the value at array(x) will contain the previous value at array(y), and the value at array(y) will contain the previous value held by array(x).

Off Topic:
Arrays are kinda 'hard to get' for people who don't already get them. If you are interested in computer programming...make the effort. It will pay off hugely. An array is simply a bunch of variables held together with a single name. As such, an array of 10 "joe"s, where the variable "joe" is an integer, can contain 10 distinct integers....just as the variable list joea, joeb, joec, ...etc. could. With arrays, instead of naming each *similar purposed* variable, you just name it once...then you can access each *similar purposed* variable by writing the name, followed by it's number. Each array variable is as independent as any 'uniquely named' variable. SO...you can do things like say:

joe(1) = 45 * t

in the same way you might say:

x = 45 * t

then, you can go on to say something like:

joe(2) = joe(1) -(2*t)

This is really powerful. Learn it. Come to terms with it.
With a single name, you can access a whole mess-o-variables...or types...or strings...or whatever!!!

Think of trying to write something like "nibbles" (you know...the snake-game). How to do it without arrays??? With arrays you say...snake1 is 100 pixels long...OK...I'll make a 100 element array...each element holding 1 pixel coordinate. Without arrays, you'd have to write, name, and keep track of 100 variables. I don't think I'd be up to the task.

Cheers, and good luck,
You're welcome,

Mango
Reply
#12
i get what oracle posted. i havent figuared out the other way[/b]
Reply
#13
Don't you start spelling my name incorrectly now, like Flex Smile Smile

My method is a "quick fix", nothing flash, and slow. But if it works for you, go ahead and use it. But I *do* reccomend that you try to figure out how the other one works.
Reply
#14
mango- i could use some more explination please.
Reply
#15
I hear BBForums are getting more violent these days.. I wonder why...? :normal:
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#16
Quote:I hear BBForums are getting more violent these days.. I wonder why...? :normal:
i dont get it
Reply
#17
:|
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#18
Quote:I hear BBForums are getting more violent these days.. I wonder why...? :normal:

Just this one Smile Because you're throwing nukes and knives around :king:
Reply
#19
Quote:mango- i could use some more explination please.

What questions do you have, specifically? Look at my first post in this thread...the one containing the program. Copy it and paste it to notepad (to maintain the indentations...needed for clarity), give it a name with a .BAS extention, then open it in QB. Then, go through it, 1 line at a time. I made it about as clear and simple as I know how...and I offered more explaination in my 2nd post. I'll be glad to continue trying to help you, but I don't really know what you need.

The best way to get help might be like you did originally...to post a small, narrowly defined problem, explain what you are trying to do, show what you've got so far, then ask for advice. The easiest advice to *give* is code that works to accomplish your goal. What exactly do you want to do?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)