mirror of https://github.com/m-labs/artiq.git
language/RandomScan: automatic seed by default
This commit is contained in:
parent
b27682ad20
commit
69ffa21133
|
@ -18,7 +18,7 @@ iterators are independent from each other.
|
||||||
Scan objects are supported both on the host and the core device.
|
Scan objects are supported both on the host and the core device.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from random import Random, shuffle
|
import random
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
from artiq.language.core import *
|
from artiq.language.core import *
|
||||||
|
@ -89,12 +89,16 @@ class LinearScan(ScanObject):
|
||||||
class RandomScan(ScanObject):
|
class RandomScan(ScanObject):
|
||||||
"""A scan object that yields a fixed number of randomly ordered evenly
|
"""A scan object that yields a fixed number of randomly ordered evenly
|
||||||
spaced values in a range."""
|
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.start = start
|
||||||
self.stop = stop
|
self.stop = stop
|
||||||
self.npoints = npoints
|
self.npoints = npoints
|
||||||
self.sequence = list(LinearScan(start, stop, 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
|
@portable
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
|
|
Loading…
Reference in New Issue