Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Excluding previously selected values.
Old
Jagatuba
Guest
 
Status:
Posts: n/a
Default Excluding previously selected values. - 08-01-2010, 05: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,
Cal
   
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2020, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.