Random number generator with conditions - Python

The question is, as pointed out by others, whether we allow correlations between the numbers being high/low and even/odd. The following code does not introduce this correlation.

import random
n = 5                                                                           
odd = 2                                                                         
high = 2                                                                        

odd_indices = random.sample(range(n), odd)                                      
high_indices = random.sample(range(n), high)                                    
out = random.sample(range(26),n)                                                
for i in range(n):                                                              
    out[i] *= 2                                                                 
    if i in odd_indices:                                                        
        out[i] += 1                                                             
    if i in high_indices:                                                       
        out[i] += 50                                                             

Please note that this includes the number 100 as output option. Strictly speaking you did not include it, so one could introduce a shift if the 100 is hit:

    if out[i]==100:
        out[i] -= random.sample(range(1,25),1)[0]*2

This code is not optimized for performance.

edit

This code will have an irregularity, though, as in each possible output 2k and 2k+1 never occur at the same time for any k.

Tags:

Python