mardi 21 février 2017

How to create selective random choices from a list

I am trying to create a Rubik's cube scrambler but in my code I will get repeated notation.

Instead of getting R2 F2 L U2, I will get repeats such as R2 R' F F2.

They basically cancel each other out and I can't have that happening. Here is my code:

import random 

posNots = ["U", "U2", "U'", "D", "D'", "D2", "F", "F'", "F2", "B",
           "B'", "B2", "R", "R'", "R2", "L", "L'", "L2",] 

def randomScramble(): 
  total = 0 
  while total <= 20:
    print random.choice(posNots)
    total = total + 1 


carl = str(randomScramble()) 

Here is a sample output showing the errors (marked with asterisks)

L2
B'
B'
R
B2
F2
L'
D2
D'
L2
D
B2
F2
D2***
D2***
D'***
F2
D2
U'
L2
L

I also eventually would like to make to code horizontal instead of vertical but I need to stop the repeats first.




Aucun commentaire:

Enregistrer un commentaire