Random generator, my ...

Discussion in 'Card Hunter General Chat' started by RNGFBS, Aug 13, 2015.

  1. Jayce

    Jayce Hydra

  2. Xayrn

    Xayrn Hydra

    Interesting analysis, but what really caught my eye as a programmer was this trick I've somehow never seen before:
    Code:
    if (j != i) {        // Classic XOR-based swap
         deck[i] ^= deck[j];   // C1 = C1_orig xor C2_orig
         deck[j] ^= deck[i];   // C2 = C2_orig xor C1_orig xor C2_orig = C1_orig
         deck[i] ^= deck[j];   // C1 = C1_orig xor C2_orig xor C1_orig = C2_orig
    }
    Also, in case anyone needs a translation...
     
    Jayce likes this.
  3. Jayce

    Jayce Hydra

    I love that swapping technique, but every time I use it, I have to go through it to remember what's going on and convince myself it's not witchcraft =D
     

Share This Page