Random number generation with a twist...

Hi everyone, I need a random number generator that will pick a number randomly, pick another number, and do so a total of 5 times, picking out of a set of 28 numbers. Pretty easy right? So here's the twist: I need to be able guarantee the 5 numbers I chose are different, but when I use it again later in the program, it needs to be able to use those numbers again. I am making a quiz game that presents you with a problem and 5 answers one being correct and linked with the question. My problem is sometimes one of the numbers gets chosen twice, and this is especially problematic when the repeated answer is the correct one. Any idea how to make one of these?

Comments

  • adamhwilkadamhwilk Member, PRO Posts: 11

    Hey. I would use a table to control it, and remove the row once it had been selected, thereby preventing it from reoccurring.

    So if you have 28 questions and answers in a table, randomly pick a row , copy the row to a new table or store it somewhere, then remove it from your original list.

    Hope this makes sense.

  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2014

    @nugget2001 said:
    I need a random number generator that will pick a number randomly, pick another number, and do so a total of 5 times, picking out of a set of 28 numbers.

    So basically you want a random selection of 5 numbers from a set 28.

    @nugget2001 said:
    Pretty easy right?

    Yeah !

    @nugget2001 said:
    So here's the twist . . .

    Ah ! :neutral_face:

    @nugget2001 said:
    I need to be able guarantee the 5 numbers I chose are different

    Given these are all text answers (so you don't have to worry about number patterning) I would just do it like this . . . .

    Change game.answerA to random (1,6)

    Change game.answerB to random (7,11)

    Change game.answerC to random (12,17)

    Change game.answerD to random (18,22)

    Change game.answerE to random (23,28)

    @nugget2001 said:
    but when I use it again later in the program, it needs to be able to use those numbers again.

    The selections will be stored in the above attributes, use them how and when you like.

    @nugget2001 said:
    I am making a quiz game that presents you with a problem and 5 answers one being correct and linked with the question.

    If one answer needs to be the correct answer (always a good ploy in a quiz :smile: ), then the 5 answers cannot be selected randomly, one will need to predetermined.

    P.S the table method by @adamhwik is a good one too.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Here's a demo to get you started.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822

    @tatiang said:
    Here's a demo to get you started.

    Nice ! :)

Sign In or Register to comment.