

of 7 runs, 10 loops each)ħ8.8 ms ± 4.22 ms per loop (mean ± std. More "normal" case (with larger sample) # Mitch's NumPy solutionġ5.6 ms ± 1.12 ms per loop (mean ± std. # Raymond Hettinger's solution (single number generation)Ħ18 µs ± 13 µs per loop (mean ± std. Uniqs = Įxtreme degenerate case # Mitch's NumPy solutionġ53 µs ± 3.71 µs per loop (mean ± std. def no_depend_gen_uniq_floats(lo, hi, n): If you cannot use NumPy, it still may be more efficient depending on your data needs to apply the same concept of checking for dupes afterwards, maintaining a set. Uniqs = np.setdiff1d(np.unique(arr), out) If you can afford NumPy doing so with np.random.uniform can be a huge speed-up.
PYTHON RANDOM LIST GENERATOR GENERATOR
Initially, I tried to use a Generator as follows: def randomnumber (NUM): List i for i in range (NUM) List.shuffle () index 0 while index < NUM: index + 1 yield List index-1 But as NUM is 233 in. For a package I am writing, I need unique numbers between 0 and 233 in a random order. In the range of low > list(FRange(low=10, high=20, num_points=5))ĭef _init_(self, low, high, num_points): Python: Alternative for a generator of HUGE list.

""" Return a k-length list of unique random floats One easy way is to keep a set of all random values seen so far and reselect if there is a repeat: import random
