Here is the basic code, I am think something along the lines of another array of type boolean. Monitoring each sub for either true or false. And if the field is false print it out, but then set that sub to true. If it falls on a sub that is true, randomly generate another sub slot instead.

Is my logic on the right path? Thanks for any help, and examples you may provide!

Re: Print out random array value with no repeats until end

Posted 11 October 2011 - 11:35 PM

So basically I have an array with 10numbers. Let's say 1-10 to make it simple. I can print out a specific sub of the array just fine randomly, but what I am trying to do is basically not print out repeating numbers until the array runs completly. So

Array[0] printed out
array[7] printed out
Array[0] tries to get printed out but its been printed out before so get another random sub
array[7] agaiin same as above
array[5] printed out
...
...

Hope this helps out. Like I said I think imma need a boolean array to do validation not sure though if there is an easier way.

Re: Print out random array value with no repeats until end

Posted 11 October 2011 - 11:42 PM

One Idea, you can use arryList/list of your numbers, then generate random number from 0 to the size of list, use it as index and print the number, then remove the already printed number from list. This will make sure you are not going to loop to infinity by waiting to the desired occurrence from random selection

Yeah, this isn't really required for my assignment. The teacher posed this to us as extra credit, and the way he explained it was basically the way I wrote it above. I don't really want to jump out of his explanation, even though it may be wrong. As is my program below works just fine, and its what he was looking for. Thanks everyone, if anyone knows how to do this without a arraylist feel free to post.

Re: Print out random array value with no repeats until end

Re: Print out random array value with no repeats until end

Posted 12 October 2011 - 04:15 PM

pbl, on 12 October 2011 - 01:58 PM, said:

You can do it with 2 arrays it will work

So something like set all values in the Boolean array to true, make the loop as i did. If the spot equals true make text area equal quote, also make that sub in the bool array false. else get another random number and try again?

I am just trying to figure out the logic, Sorry to be such a bother with what seems to be an unconventional form of programming. =/