Random Source: Difference between revisions
(Rectifying misleading random number quality) |
No edit summary |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
[[Category:Block Docs]] | [[Category:Block Docs]] | ||
Generates a number of samples of random numbers of [min, max) meaning the max value won't be included. Repeat samples if specified. | Generates a number of samples of random numbers of [min, max) meaning the max value won't be included. Repeat samples if specified. Useful for creating bytes of information for testing a modulator. | ||
Ex: With min=0 and max=2, the sequence 01110101... will be generated. | Ex: With <code>min=0</code> and <code>max=2</code>, the sequence 01110101... of length <code>num_samps</code> will be generated. | ||
Supports an output of type int, short, and byte. | Supports an output of type int, short, and byte. | ||
Line 8: | Line 8: | ||
This block differs from [[Random Uniform Source]]: | This block differs from [[Random Uniform Source]]: | ||
This block uses Numpy to generate a fixed random vector of values. The output of this block repeats every <code> | This block uses Numpy to generate a fixed random vector of values. The output of this block repeats every <code>num_samps</code>, and hence has high autocorrelation with that period.<br> | ||
The algorithms used to generate the random numbers differ, as well: Numpy, and hence Random Source, use https://en.wikipedia.org/wiki/Mersenne_Twister MT19937] | The algorithms used to generate the random numbers differ, as well: Numpy, and hence Random Source, use [https://en.wikipedia.org/wiki/Mersenne_Twister MT19937]¹, whereas the [[Random Uniform Source]] uses [https://xoroshiro.di.unimi.it/xoroshiro128plus.c XOROSHIRO128+], which has a period of 2<sup>128</sup>-1 and is hence to be preferred if autocorrelation over a window of length <code>num_samps</code> is relevant. | ||
This block does not support C++ output, so it cannot be used when the output language of a flowgraph in GRC is C++. | |||
== Parameters == | == Parameters == | ||
(''R''): <span class="plainlinks">[https://wiki.gnuradio.org/index.php/GNURadioCompanion#Variable_Controls ''Run-time adjustable'']</span> | (''R''): <span class="plainlinks">[https://wiki.gnuradio.org/index.php/GNURadioCompanion#Variable_Controls ''Run-time adjustable'']</span> | ||
; | ; Output type | ||
: | : Available options are int, short or byte | ||
; Minimum | |||
: The lower limit of the range of generated values (included in the output) | |||
; Maximum | |||
: The upper limit of the range of generated values (not included in the output) | |||
; | ; Num Samples | ||
: | : Total number of samples that are generated in the output | ||
; Repeat | |||
: Yes/No | |||
== Example Flowgraph == | == Example Flowgraph == | ||
Line 36: | Line 47: | ||
; Block definition | ; Block definition | ||
: [https://github.com/gnuradio/gnuradio | : [https://github.com/gnuradio/gnuradio/blob/main/gr-analog/grc/analog_random_source_x.block.yml analog_random_source_x.block.yml] | ||
== Computational Performance == | |||
[[File:Benchmark prng.grc|alt=Benchmarking]] done on a Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz, 8GB RAM VOLK 2.5.0, GNU Radio 3.10.0.0-rc1, Linux 5.15.11 | |||
[[File:Benchmark prng.png]] | |||
{| class="wikitable" | |||
|- | |||
! Block | |||
! Number of Samples / Period after which samples repeat | |||
! Throughput (in 10<sup>6</sup> samples per second) | |||
! Note | |||
|- | |||
| Random Source | |||
| 1000 | |||
| 838 | |||
| default setting | |||
|- | |||
| Random Source | |||
| 2<sup>20</sup>=1,048,576 | |||
| 824 | |||
|- | |||
| Random Source | |||
| 2<sup>24</sup> | |||
| 812 | |||
|- | |||
| Random Source | |||
| 2<sup>28</sup> | |||
| 813 | |||
| Initialization of the random vector needs nearly 30s, eats 4GB of RAM | |||
|- | |||
| | |||
|- | |||
| Random Uniform Source | |||
| 2<sup>128</sup>-1 | |||
| 282 | |||
| | |||
|} | |||
---- | |||
¹ The slightly superior randomness properties of MT19937 over XOROSHIRO128+ don't matter within the maximum size of a vector of values on a PC, and are generally unnoticable in an SDR contex |
Latest revision as of 05:52, 20 January 2022
Generates a number of samples of random numbers of [min, max) meaning the max value won't be included. Repeat samples if specified. Useful for creating bytes of information for testing a modulator.
Ex: With min=0
and max=2
, the sequence 01110101... of length num_samps
will be generated.
Supports an output of type int, short, and byte.
This block differs from Random Uniform Source:
This block uses Numpy to generate a fixed random vector of values. The output of this block repeats every num_samps
, and hence has high autocorrelation with that period.
The algorithms used to generate the random numbers differ, as well: Numpy, and hence Random Source, use MT19937¹, whereas the Random Uniform Source uses XOROSHIRO128+, which has a period of 2128-1 and is hence to be preferred if autocorrelation over a window of length num_samps
is relevant.
This block does not support C++ output, so it cannot be used when the output language of a flowgraph in GRC is C++.
Parameters
(R): Run-time adjustable
- Output type
- Available options are int, short or byte
- Minimum
- The lower limit of the range of generated values (included in the output)
- Maximum
- The upper limit of the range of generated values (not included in the output)
- Num Samples
- Total number of samples that are generated in the output
- Repeat
- Yes/No
Example Flowgraph
Source Files
- C++ files
- TODO
- Header files
- TODO
- Public header files
- TODO
- Block definition
- analog_random_source_x.block.yml
Computational Performance
File:Benchmark prng.grc done on a Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz, 8GB RAM VOLK 2.5.0, GNU Radio 3.10.0.0-rc1, Linux 5.15.11
Block | Number of Samples / Period after which samples repeat | Throughput (in 106 samples per second) | Note |
---|---|---|---|
Random Source | 1000 | 838 | default setting |
Random Source | 220=1,048,576 | 824 | |
Random Source | 224 | 812 | |
Random Source | 228 | 813 | Initialization of the random vector needs nearly 30s, eats 4GB of RAM |
Random Uniform Source | 2128-1 | 282 |
¹ The slightly superior randomness properties of MT19937 over XOROSHIRO128+ don't matter within the maximum size of a vector of values on a PC, and are generally unnoticable in an SDR contex