2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-28 20:53:35 +08:00

language/RandomScan: automatic seed by default

This commit is contained in:
Sebastien Bourdeauducq 2016-05-23 14:29:42 -07:00
parent b27682ad20
commit 69ffa21133

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):