How do I generate random numbers including 1 fixed value?

0 favourites
  • 5 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • Hi.

    I'm trying to make a quiz game where all the answers are single alphabet letters.

    Questions are given with pictures.

    For example, a picture of a frog is given as a question, then four alphabets are given to choose from.

    The player is to guess the first letter of the object in the picture.

    (In this case, F)

    Here, I want the four given letters to be one correct answer and the rest to be not repeating random letters(out of 25 other alphabet letters).

    How can I do this?

    I've studied some of the related tutorials but none of them uses random answers out of a answer pool.

    Please help.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • First, place the correct answer/value in a random position. Store this value so that you have something to compare the user answer with as well as to check against a duplicate when picking random values in the next step. For each of the remaining three positions, chose a random non repeating letter by using the advanced random plugin. If the correct answer is randomly picked, then ignore that result and use the next result.

    To use the advanced random plugin, first use the create permutation table action with offset 1 and length 26. This will generate the numbers from 1 to 26 and then randomly shuffle them, each one corresponding to a letter of the alphabet. To retrieve the values, use the AdvancedRandom.Permutation expression, where AdvancedRandom.Permutation(0) would be the first value, AdvancedRandom.Permutation(1) would be the second, and so on.

    So for each answer choice that isn't the correct one, put the next permutation value in sequence (since they're already shuffled), only if the value doesn't match the correct choice. If it does, skip that permutation and continue with the next.

  • First, place the correct answer/value in a random position. Store this value so that you have something to compare the user answer with as well as to check against a duplicate when picking random values in the next step. For each of the remaining three positions, chose a random non repeating letter by using the advanced random plugin. If the correct answer is randomly picked, then ignore that result and use the next result.

    To use the advanced random plugin, first use the create permutation table action with offset 1 and length 26. This will generate the numbers from 1 to 26 and then randomly shuffle them, each one corresponding to a letter of the alphabet. To retrieve the values, use the AdvancedRandom.Permutation expression, where AdvancedRandom.Permutation(0) would be the first value, AdvancedRandom.Permutation(1) would be the second, and so on.

    So for each answer choice that isn't the correct one, put the next permutation value in sequence (since they're already shuffled), only if the value doesn't match the correct choice. If it does, skip that permutation and continue with the next.

    Thank you for the detailed reply.

    Thanks to your explanation I got an idea where to start.

    But since I'm not so familiar with construct3,(actually I'm noob to any kind of game making) I have hard time implementing the idea into actual project.

    Could youn please elaborate a little more including some example expressions?

  • dropbox.com/s/sujrkr4imdx6o59/quizanswersexample.c3p

    Thank you so much!

    This has been a great help.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)