Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

A way to compare random numbers?

Featured Replies

  • 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.... confused.gif

Thanks in advance

/nic

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.

  • 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 your 5 fields

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

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.