Randomize two variables with no repetition

  • How do I randomize two variables with, let's say two values without any repetition? For example, I have both A and B variable, which I'm going to set 0 and 1 for each other, whereas I need to avoid the A and B to set to 0 and 0 / 1 and 1 respectively. Sorry if this is obvious to you.

  • Creating a random number you use random(1,1000) << This is to create a random number between 1 and 1000.

    It will also create for instance 234,3049. So to round it down you use round(random(1,1000)). I hope this helps you more with what you're trying to do.

  • Here's an example where when you press "S" on your keyboard the text changes to a random number between 1 and 1000.

  • So you want to toggle them (more/less)

    if A=0 then B=1

    if A=1 then B=0

    ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm not quite sure what you're trying to do other than give them random numbers. Please gie me more detail on what you're trying to do.

  • I'm taking a wild guess here at exactly what you want..

    Create an Array with the values that are the 'pool' of numbers to choose randomly from. Each time you choose 2 (or whatever) random numbers from this list (by index) remove them from the Array (using delete), so they cannot be repeated in further choices.

    I'm using this technique when choosing where to spawn enemies, when there is a fixed number of 'zones' in which to spawn, and I don't want any spawning on the same zone.

    If what you really want is just 0 and 1 as in your example, then there are simpler ways.

  • Here's a example to illustrate this situation:

    Assume I have excess numbers of apple and orange, which I will randomly choose four of them to put in four baskets respectively, in the form of 2 apples and 2 oranges exactly.

    I've just tried my best to explain it, but I think it's related to permutation or combination.

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