0.2.1 DEVRANDOM

This commit is contained in:
rob tillaart 2022-10-31 19:50:00 +01:00
parent 08e1246a9a
commit da486d9938
7 changed files with 84 additions and 39 deletions

View File

@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
@ -7,5 +22,7 @@ compile:
# - leonardo
- m4
- esp32
# - esp8266
# - mega2560
- esp8266
# - mega2560
- rpipico

View File

@ -0,0 +1,37 @@
# Change Log DEVRANDOM
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.2.1] - 2022-10-31
- add changelog.md
- add rp2040 to build-CI
## [0.2.0] - 2022-07-02
- add Marsaglia PRNG, is portable over platforms, becomes mode 3
- improved reseeding
- split off .cpp file
- add examples
----
## [0.1.3] - 2021-12-15
- update library.json
- license
- minor edits
## [0.1.2] - 2021-01-15
- add constructors with seed.
## [0.1.1] - 2022-07-01
- add Arduino-CI + unit tests
- add getMode()
- add flush()
## [0.1.0] - 2020-06-23
- initial version

View File

@ -5,18 +5,7 @@
// PURPOSE: Arduino library for a /dev/random stream - useful for testing
// URL: https://github.com/RobTillaart/DEVRANDOM
//
// HISTORY:
// 0.1.0 2020-06-23 initial version
// 0.1.1 2020-12-18 add Arduino-CI + unit tests
// + getMode() + flush()
// 0.1.2 2021-01-15 add constructors with seed.
// 0.1.3 2021-12-15 update library.json, license, minor edits
//
// 0.2.0 2022-07-02 add Marsaglia PRNG, is portable over platforms
// becomes mode 3
// improved reseeding
// split off .cpp file
// add examples
// HISTORY: see changelog.md
#include "DEVRANDOM.h"
@ -69,7 +58,7 @@ int DEVRANDOM::read()
};
// keep CI happy as parent class flush is virtual.
// keep CI happy as parent class flush is virtual.
void DEVRANDOM::flush()
{
};
@ -168,9 +157,9 @@ int DEVRANDOM::_analogRead()
}
// An example of a simple pseudo-random number generator is the
// Multiply-with-carry method invented by George Marsaglia.
// two initializers (not null)
// An example of a simple pseudo-random number generator is the
// Multiply-with-carry method invented by George Marsaglia.
// two initializers (not null)
uint32_t DEVRANDOM::_marsaglia()
{
_m_z = 36969L * (_m_z & 65535L) + (_m_z >> 16);

View File

@ -2,7 +2,7 @@
//
// FILE: DEVRANDOM.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.0
// VERSION: 0.2.1
// PURPOSE: Arduino library for a /dev/random stream - useful for testing
// URL: https://github.com/RobTillaart/DEVRANDOM
//
@ -11,7 +11,7 @@
#include "Arduino.h"
#define DEVRANDOM_LIB_VERSION (F("0.2.0"))
#define DEVRANDOM_LIB_VERSION (F("0.2.1"))
#define DEVRANDOM_MODE_RANDOM 0
@ -31,9 +31,11 @@ public:
int available();
int peek();
int read();
// keep CI happy as parent class flush is virtual.
// keep CI happy as parent class flush is virtual.
void flush();
// for reseeding, including via print() and println().
// for reseeding, including via print() and println().
size_t write(const uint8_t data);
size_t write(const uint8_t * buffer, size_t size);
@ -46,10 +48,10 @@ public:
uint8_t getMode();
// will be obsolete in future
void useAR(uint8_t pin) { useAnalogRead(pin); };
void useHW(uint8_t pin) { useDigitalRead(pin); };
void useSW() { useRandom(); };
// OBSOLETE
// void useAR(uint8_t pin) { useAnalogRead(pin); };
// void useHW(uint8_t pin) { useDigitalRead(pin); };
// void useSW() { useRandom(); };
private:
@ -57,7 +59,8 @@ private:
uint32_t _seed = 0;
uint8_t _mode = 0;
uint8_t _pin = 0;
// Marsaglia 'constants'
// Marsaglia 'constants'
uint32_t _m_w = 1;
uint32_t _m_z = 2;

View File

@ -65,12 +65,12 @@ The seed value from the write is used as a XOR byte.
This one is quite fast and good, and more important portable.
- **uint8_t getMode()** returns the source of randomness.
| Mode | DEVRANDOM_MODE | Type |
|:-------:|:----------------:|:----------------------|
| 0 | build in random | depends on platform
| 1 | digitalRead | hardware external
| 2 | analogRead | hardware external
| 3 | Marsaglia | software portable PRNG
| Mode | DEVRANDOM_MODE | Type |
|:-------:|:----------------:|:-----------------------|
| 0 | build in random | depends on platform |
| 1 | digitalRead | hardware external |
| 2 | analogRead | hardware external |
| 3 | Marsaglia | software portable PRNG |
There might be other RNG's in the future.
@ -79,8 +79,6 @@ If you have an interesting and fast PRNG to be included please let me know.
### Obsolete
To be obsolete in a next release.
- **useSW()** replaced by **useRandom()**.
- **useHW(uint8_t pin)** replaced by **useDigitalRead()**.
- **useAR(uint8_t pin)** replaced by **useAnalogRead()**.
@ -93,7 +91,7 @@ See example sketches.
### Example
As shown in the example one can use fscanf to read larger datatypes,
As shown in the example one can use fscanf() to read larger data types,
```cpp
DEVRANDOM dr;
@ -101,7 +99,8 @@ As shown in the example one can use fscanf to read larger datatypes,
fscanf((FILE*) &dr, "%lu", &x);
Serial.println(x);
```
However float is not supported standard in the fscanf by UNO and strings (%s) generate garbage.
However float is not supported standard in the fscanf() by UNO and strings (%s) generate garbage.
So a password generator is a bit more difficult (and a good exercise).

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/DEVRANDOM.git"
},
"version": "0.2.0",
"version": "0.2.1",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=DEVRANDOM
version=0.2.0
version=0.2.1
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library to wrap a random generator in a stream