Posted: Sun Jan 16, 2011 4:04 pm Post subject: Re: How to not repeat a number when using randint?
Can anyone just show me so I can understand from it than pull out my hair?
Tony
Posted: Sun Jan 16, 2011 4:08 pm Post subject: RE:How to not repeat a number when using randint?
There's quite a lot of difference between "here's a complete solution to copy" and actually understanding the material well enough to write the solution yourself.
Besides, TokenHerbz already provided a working example.
Posted: Tue Jan 18, 2011 7:44 pm Post subject: RE:How to not repeat a number when using randint?
My gr. 10 teacher didn't teach us about that particular type of data structure, thats why I had to ask you about that init. My knowledge of them was reverse engineered based on an example program.
Either he/she doesn't know about them, then mercifully teach him/her about them and how to store each variable into it and run through it before randomizing (that was a hint).
Tony
Posted: Tue Jan 18, 2011 8:00 pm Post subject: RE:How to not repeat a number when using randint?
One doesn't _need_ arrays for this. They are just more convenient than having 10 separate variables.
Alternatively, (because everybody knows of an int type), a single integer can be used as a bitfield (http://en.wikipedia.org/wiki/Bit_field); for just 10 numbers, the "bits" could remain entirely in decimal form too. Another neat solution in place of bitfields is a sum of primes.
Posted: Thu Jan 20, 2011 4:20 pm Post subject: RE:How to not repeat a number when using randint?
Ok, I'll lend a hand. First off, if you haven't worked with arrays, this may seem difficult but you will catch on.
First we have to declare everything that will make the program work. What do we need? Well first and foremost you need it to be able to read a random number between 1 and 6 of a die.
Next we need to somehow store the values already retrieved. For this we need to use an array. If you haven't used an array before here is the basic format. I won't give away what to put in each place though.
Now that we have declared the required variables we can move on to the actual program.
The first thing that needs to occur is the rolling of the die.
Next, we need to check and see if that number was found already. We do this by checking the array. What statement type can be used here to run through a minimum to a maximum number?
If the number was found you can have it display a message, otherwise...
We need it store the value of the die that was rolled.
Display a message of what was rolled.
That's my walk-through of everything that needs to be done. Hopefully its clear enough and can bring some understanding to the matter.