RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[XP] How to make random number w/c do not produce duplicate value?

0 Members and 1 Guest are viewing this topic.

**
Rep:
Level 67
RMRK Junior
I am trying to have a random set of questions.
i tried having a variable with a random value of 1-5.
and conditional branch of which the value of the variable is selected then the question is the same number.
E.G Control Variable[001: RandomNum] = Random No. (1...5)
Conditional Branch: Variable [001: RandomNum] == 1
 Text: Question number 1

Conditional Branch: Variable [001: RandomNum] == 2
 Text: Question number 2
and so on....

but my problem is, random number is sometimes duplicating like 1-2-2-3-2. so the questions are being repeated. i need it not being repeated.

hoping for your help guys. Thanks !

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, one way would be to use self-switches inside a loop, like this:

Loop
  Control Variable[001:RandomNum] = Random No. (1..5)
  Conditional Branch: Variable [001: RandomNum] == 1
    Conditional Branch: Self-Switch A is OFF
      Question Number 1
      Control Self-Switch: A = ON
      Break Loop
    Branch End
  Branch End
  Conditional Branch: Variable [001: RandomNum] == 2
    Conditional Branch: Self-Switch B is OFF
      Question Number 2
      Control Self-Switch: B = ON
      Break Loop
    Branch End
  Branch End
  ...
Repeat Above

It's a bit of a pain and you could only have four though (unless you use game_guy's More Self Switches script). You'd also need a way to break the loop immediately if no more questions were left.

You could also do the same, except using a variable instead of self-switches to track which questions have been answered. For the first question, you'd add 1 to the tracking variable. For the second question, you'd add 2; for the third question you'd add 4; for the fourth question you'd add 8; for the nth question you'd add 2^n-1, etc... Then you could know whether each question has been asked before by looking at that tracking variable.

However, I don't really see the point of randomizing the questions if you need to have them all asked anyway? It's a lot of work for a feature of questionable value.
 

Also, there might be an easier way to do it, but that's the first that came to my mind. I have a sunburn though, so I'm not really thinking clearly.
« Last Edit: July 25, 2011, 04:43:52 PM by modern algebra »

**
Rep:
Level 67
RMRK Junior
Thanks for your reply.. this would be a great help. i think i'll just substittue the self-switch with a variable.  ;D
« Last Edit: July 27, 2011, 02:25:07 PM by kenth21v »

*
? ? ? ? ? ? ? ? ? The nice kind of alien~
Rep:
Level 92
Martian - Occasionally kind
Well, one way would be to use self-switches inside a loop, like this:

Loop
  Control Variable[001:RandomNum] = Random No. (1..5)
  Conditional Branch: Variable [001: RandomNum] == 1
    Conditional Branch: Self-Switch A is OFF
      Question Number 1
      Control Self-Switch: A = ON
      Break Loop
    Branch End
  Branch End
  Conditional Branch: Variable [001: RandomNum] == 2
    Conditional Branch: Self-Switch B is OFF
      Question Number 2
      Control Self-Switch: B = ON
      Break Loop
    Branch End
  Branch End
  ...
Repeat Above

I suggest you do it this way. It's simply way too dangerous. First of all who knows how many rounds it can take, secondly and most importantly the loop becomes an infinite loop the 6th time it's called. You can clean it up and protect it, but having some code which will freeze the game if you miss a route into the loop a 6th time is not nice at all.

Luckily only some slight alteration are needed to make the loop safer.

Control Variable[001:RandomNum] = Random No. (1..5)
Loop
  Conditional Branch: Variable [001: RandomNum] <= 1
    Conditional Branch: Self-Switch A is OFF
      Question Number 1
      Control Self-Switch: A = ON
      Break Loop
    Branch End
  Branch End
  Conditional Branch: Variable [001: RandomNum] <= 2
    Conditional Branch: Self-Switch B is OFF
      Question Number 2
      Control Self-Switch: B = ON
      Break Loop
    Branch End
  Branch End

  ...

  Conditional Branch: Variable [001: RandomNum] <= 5
    Conditional Branch: Self-Switch B is OFF
      Question Number 5
      Control Self-Switch: B = ON
      Break Loop
    Branch End
  Branch End
  Control Variable[001:RandomNum] -= 1
  Conditional Branch: Variable [001: RandomNum] <= 0
    Break Loop
  Branch End
Repeat Above


Personally I would use an extra variable to keep track of the number of questions left so I wouldn't need to use a loop at all, but practically I doubt there are any significant difference with only 5 questions.

*hugs*

**
Rep:
Level 67
RMRK Junior
here is what i did:
Loop
Control Variables: [0010: RandomQues] = Random No. (1...20) --->>> for 20 sets of questions
 Conditional Branch: Variable [0010: RandomQues] == 1
   Conditional Branch: Variable [0026: q1] == 0
      Text: QUESTION
      Control Variables: [0011: NuumberofQuestion] += 1
      Control Variables: [0026: q1] += 1
    Else
    Conditional Branch: Variable [0011: NumberofQuestion] == 5
       Break Loop
     Branch End
   Branch End
 Branch End
Conditional Branch: Variable [0010: RandomQues] == 2
..... and so on....
Conditional Branch: Variable [0011: NumberofQuestion] == 5
       Break Loop
Branch End
Repeat Above

it works fine,
so thanks to everybody!  ;D