View Single Post
Excluding previously selected values.
Posts: n/a
Default Excluding previously selected values. - 08-01-2010, 04:36 PM

Hi All,

Although I am somewhat new to using Alice, I have caught on to most of the program's functionality. However, I am having trouble creating method to choose a random number.

I do know how to use variables and the random number function. However, I'm having trouble coming up with a logic that chooses a different random number each time the method is called.

It's tricky because here is what I want to do. I want to have an array called questionArray. This array will be populated with a number of questions that I want to ask the user at random. However, I do not want to repeat a question if it has already been asked.

It seems simple at first glance.

Create a checkArray.
Set randomNumber between 0 and size of questionArray.
Check randomNumber against all the values of the checkArray.
If the randomNumber is not equal to any of the numbers in checkArray,
Add it to the next index slot of checkArray then
Display item randomNumber in questionArray.
Else select a new randonNumber and perform the check again.

This was my initial instinct, but I found myself banging my head as it seems to require several nested loops, which get quite confusing quickly. I seem to be lost at how to solve this problem. Does anybody have any suggestions on how to solve construct this?

If I can just get a method constructed that returns a different random number every time, I think I can handle the rest of the logic involving question selection and display.

Thanks in advance,
Reply With Quote