Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. How can i randomly select from 1-10 with out repeating the same number in the process
Forum Updated to NodeBB v4.3 + New Features

How can i randomly select from 1-10 with out repeating the same number in the process

Scheduled Pinned Locked Moved Game Development
6 Posts 4 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Newbie
    wrote on last edited by
    #1

    is there any posible way to control the output of the codes "Math.floor(Math.random()*10+1)" as in everytime it generates a new number it wont generate the same number it previously have. like for example i use math random to generate a question out of 10 questions at first it pick the 3rd question now the next time it will generate another question it will not choose the 3d question again..

    1 Reply Last reply
    0
    • T Offline
      T Offline
      task_struct
      wrote on last edited by
      #2

      Hello,

      This might help you: "Permutation":http://en.wikipedia.org/wiki/Permutation#Random_generation_of_permutations

      "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

      • Linu...
      1 Reply Last reply
      0
      • L Offline
        L Offline
        lgeyer
        wrote on last edited by
        #3

        In other words, no. You will have to add some extra logic to filter out duplicate random numbers.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          Newbie
          wrote on last edited by
          #4

          ow i see is it possible to put it somewhere like arrays???

          1 Reply Last reply
          0
          • T Offline
            T Offline
            task_struct
            wrote on last edited by
            #5

            Yes. You store indexes of your questions in an array. Than you just get questions[ ramdomized_indexes[ index ] ], where index increases from 0, when user answers a question. ramdomized_indexes is generated when application start.

            "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

            • Linu...
            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Basically, this is a card shuffling problem. You can google for that, or for "array shuffle".

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved