-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e29a46
commit deaa492
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from random import Random | ||
|
||
|
||
class LinearScan: | ||
def __init__(self, min, max, npoints): | ||
self.min = min | ||
self.max = max | ||
self.npoints = npoints | ||
|
||
def _gen(self): | ||
r = self.max - self.min | ||
d = self.npoints - 1 | ||
for i in range(self.npoints): | ||
yield r*i/d + self.min | ||
|
||
def __iter__(self): | ||
return self._gen() | ||
|
||
|
||
class RandomScan: | ||
def __init__(self, min, max, npoints, seed=0): | ||
self.min = min | ||
self.max = max | ||
self.npoints = npoints | ||
self.seed = 0 | ||
|
||
def _gen(self): | ||
prng = Random(self.seed) | ||
r = self.max - self.min | ||
for i in range(self.npoints): | ||
yield prng.random()*r + self.min | ||
|
||
def __iter__(self): | ||
return self._gen() |