language/RandomScan: automatic seed by default

This commit is contained in:
Sebastien Bourdeauducq 2016-05-23 14:29:42 -07:00
parent 42c84e0c72
commit aa26b13816
1 changed files with 7 additions and 3 deletions

View File

@ -18,7 +18,7 @@ iterators are independent from each other.
Scan objects are supported both on the host and the core device.
"""
from random import Random, shuffle
import random
import inspect
from artiq.language.core import *
@ -89,12 +89,16 @@ class LinearScan(ScanObject):
class RandomScan(ScanObject):
"""A scan object that yields a fixed number of randomly ordered evenly
spaced values in a range."""
def __init__(self, start, stop, npoints, seed=0):
def __init__(self, start, stop, npoints, seed=None):
self.start = start
self.stop = stop
self.npoints = npoints
self.sequence = list(LinearScan(start, stop, npoints))
shuffle(self.sequence, Random(seed).random)
if seed is None:
rf = random.random
else:
rf = Random(seed).random
random.shuffle(self.sequence, rf)
@portable
def __iter__(self):