checking if a random value exists from previous loop
<p>I'm trying to generate a random value for each loop and save it to variable <code>minimum</code> WHILE doing a check if that number has already been generated  before in one of the previous loops. </p>

<p><code>listQ</code> basically contains <strong>6 lines</strong> that were randomly chosen from a file. The lines were chosen from  between <code>1</code> to <code>max_line</code> (which is basically 6 steps less than <code>max_line</code> value). So it's important that I have to generate a number that's a multiplier of 6.</p>

<pre><code>for x in range(0, 10):
    minimum = random.randrange(0, max_line,6)
    maximum = minimum+6
    listQ = listQ[minimum:maximum]
</code></pre>

<p>A bit stuck here. A list maybe?</p>

<p>Keep a list of all the previous values and check each subsequent iteration.</p>

<pre><code># sets have faster "val in set?" checks than lists
# do this once, somewhere in your program
previous_vals = set()

# other stuff here, including main program loop
for x in range(0, 10):
    # find a unique, new random number while 
    # limiting number of tries to prevent infinite looping
    number_of_tries = 0
    MAX_TRIES = 10
    generating_random = true
    while generating_random:    
        minimum = random.randrange(0, max_line,6)
        if minimum not in previous_vals:
            previous_vals.add(minimum)
            generating_random = false
        number_of_tries += 1
        if number_of_tries == MAX_TRIES:
            raise RunTimeError("Maximum number of random tries reached!")

    maximum = minimum+6
    listQ = listQ[minimum:maximum]
</code></pre>

<p>Note that <a href="https://docs.python.org/2/library/stdtypes.html#set.add" rel="nofollow">there are other functions for <code>set</code> than add</a> if you want to modify your example. </p>

<p>I added a maximum number of tries too in order to prevent your code from getting stuck in an infinite loop, since I don't know anything about your input data to know what the likilhood of getting into this situation is.</p>

python loops random