# A way to compare random numbers?

This topic is 7009 days old. Please don't post here. Open a new topic instead.

## Recommended Posts

• Newbies

Hi all!

I have 5 fields. 4 fields gets one random number each that represents false answers to a question, Field=1 Field=2 Field=3 Field=4. The 5th field automatically fetches a number that represents the right answer to the question. For simplicity we assume that the right answer shows up i field5. In the application the right answer is randomly placed i Field 1-5.

So what I'm basically doing is posing a question and 5 possible answers show up on screen. 1 is correct and 4 is false.

1. Now, my problem is that from time to time there can be 2 (or more) identical incorrect answers showing up. Example: Field1= 45 Field2 = 13 Field3= 567 Field4 = 13 Field5= 435 (correct answer).

What I want to do is to check if there are any equal numbers in the fields, and if so, randomize the 4 fields with the incorrect answers again BUT

2. The next problem is that from time to time 2 (or more) correct answers show up. Example:Field1= 45 Field2 = 435 Field3= 567 Field4= 13 Field5 = 435

So I need to check which field that displays the correct answer, and then randomize the other 4 fields and do same checking again until there are 5 unique numbers in the 5 fields.

So what i need to do is the following:

* check in which field the correct answer is displayed and "lock" it.

* compare the 4 fields with incorrect answers. 1. Are there any equal numbers? 2. Are there the same number as in the field with the correct answer?

* If there are equal numbers in the incorrect answers, randomize again until there are 4 unique numbers and none of them is the same as in the field with the corect answer.

* If there are the same number in the field with the correct number as in any of the fields with the incorrect numbers, randomize the 4 fields with the incorrect answers again until there are 5 unique numbers in the answerfields.

I guess this can be solved with some kind of nested loop, but I just can't figure out HOW........I appreciate all help I can get in solving this little puzzle....

/nic

##### Share on other sites

It might be easier to change the order of the things around a bit. I would first generate a list of 4 unique, incorrect, random numbers. This would be a loop, generating a random number into a temp field, then - if this number is indeed incorrect and not already in the list - add it to the list.

When you have your 4 numbers, insert the correct answer at a random position in the list. The 5 fields can be calculation fields, each showing one value from the list.

##### Share on other sites

• 2 months later...

i am doing exactly this, it is complicates, im sure you can do better than what ive done, but here it is anyway:

have calc fields = to your 5 fields

have a global random value

have 5 display calc fields, so if(randomfield < 0.1, fieldset1, if (randomfield < 0.2, fieldset2.... etc))

you have to engineer the duplicate fields so that for any random value, all results are displayed

##### Share on other sites

This topic is 7009 days old. Please don't post here. Open a new topic instead.

## Create an account

Register a new account