mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.2.5 randomHelpers
This commit is contained in:
parent
f121659f29
commit
6547c372d2
@ -1,11 +1,28 @@
|
||||
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
|
||||
# selected only those that work
|
||||
platforms:
|
||||
- uno
|
||||
- due
|
||||
- zero
|
||||
- leonardo
|
||||
# - due
|
||||
# - zero
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
- esp8266
|
||||
- mega2560
|
||||
# - mega2560
|
||||
- rpipico
|
||||
|
40
libraries/randomHelpers/CHANGELOG.md
Normal file
40
libraries/randomHelpers/CHANGELOG.md
Normal file
@ -0,0 +1,40 @@
|
||||
# Change Log randomHelpers
|
||||
|
||||
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.5] - 2022-11-23
|
||||
- add changelog.md
|
||||
- add RP2040 to build-CI
|
||||
- fix license (started 2015)
|
||||
|
||||
|
||||
## [0.2.4] - 2022-04-15
|
||||
- fix #4 split .h in .h and .cpp
|
||||
|
||||
## [0.2.3] - 2021-12-27
|
||||
- update library.json, license,
|
||||
- minor edits
|
||||
|
||||
## [0.2.2] - 2021-11-15
|
||||
- update Arduino-CI, readme.md badges
|
||||
- add seedMarsaglia(uint32_t a, uint32_t b)
|
||||
- fix randomDice()
|
||||
|
||||
## [0.2.1] - 2021-01-07
|
||||
- Arduino-CI
|
||||
|
||||
## [0.2.0] - 2020-07-01
|
||||
- rewrite
|
||||
|
||||
----
|
||||
|
||||
## [0.1.01] - 2015-08-18
|
||||
- bug fixes and further optimizations
|
||||
|
||||
## [0.1.00] - 2015-08-17
|
||||
- initial version.
|
||||
|
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-2022 Rob Tillaart
|
||||
Copyright (c) 2015-2022 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -26,18 +26,21 @@ However above 16 bits the overhead is larger than the gain.
|
||||
So to improve in that range too one could use a faster random function like the one
|
||||
from Marsaglia (included).
|
||||
|
||||
Note the gains differ per platform and are more explicit on the Arduino UNO platform
|
||||
than on an ESP32.
|
||||
Note the gains differ per platform and are more explicit on the (slow) Arduino UNO
|
||||
platform than on a much faster ESP32.
|
||||
|
||||
This library relates to https://github.com/RobTillaart/Prandom
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
functions implemented are
|
||||
#### generators (sort of)
|
||||
|
||||
- **uint32_t Marsaglia()** fast PRNG.
|
||||
- **bool seedMarsaglia(uint32_t a, uint32_t b)** seed the Marsaglia PRNG. a and b should not be 0. returns true on success.
|
||||
|
||||
#### getters (sort of)
|
||||
- **bool getRandom1()** returns 0 or 1, false or true.
|
||||
- **bool flipCoin()** A wrapper around getRandom1().
|
||||
- **uint8_t getRandom4()** returns 0 .. 15.
|
||||
- **uint8_t getRandom5()** returns 0 .. 31.
|
||||
- **uint8_t getRandom6()** returns 0 .. 63.
|
||||
@ -47,11 +50,18 @@ functions implemented are
|
||||
- **uint32_t getRandom32()** returns 0 .. 2^32 - 1 (4 bytes) this is the core random generator
|
||||
- **uint64_t getRandom64()** returns 0.. 2^64 - 1 (8 bytes).
|
||||
- **uint32_t getRandomBits(n)** returns 0.. 2^n - 1 This works well for 1..16 bits but above 16 it is slower than the standard way.
|
||||
|
||||
#### Typical wrappers.
|
||||
|
||||
- **bool flipCoin()** A wrapper around getRandom1().
|
||||
- **uint8_t throwDice()** returns 1..6.
|
||||
|
||||
The examples show how to use these and how their performance gain relative to
|
||||
calling **random()** for every random number.
|
||||
|
||||
## Performance
|
||||
|
||||
to elaborate
|
||||
|
||||
## Operation
|
||||
|
||||
@ -60,8 +70,20 @@ See examples
|
||||
|
||||
## Future
|
||||
|
||||
#### must
|
||||
- improve/update documentation
|
||||
- add performance figures
|
||||
|
||||
#### should
|
||||
- wrap all up in a class.
|
||||
- add JKISS? other RNG's
|
||||
|
||||
#### could
|
||||
- improve performance getRandomBits(n) for n = 17..31
|
||||
- investigate new tricks :)
|
||||
- wrap all up in a class.
|
||||
- test if the functions are uniform.
|
||||
- rename getRandom64() ==> get64() etc.
|
||||
- when it is part of a class.
|
||||
- add **getRandom2(), getRandom3(), getRandom12()**?
|
||||
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/randomHelpers.git"
|
||||
},
|
||||
"version": "0.2.4",
|
||||
"version": "0.2.5",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=randomHelpers
|
||||
version=0.2.4
|
||||
version=0.2.5
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library with helper function for faster random bits
|
||||
|
@ -2,20 +2,10 @@
|
||||
//
|
||||
// FILE: randomHelpers.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.4
|
||||
// VERSION: 0.2.5
|
||||
// PURPOSE: Arduino library with helper function for faster random bits
|
||||
// URL: https://github.com/RobTillaart/randomHelpers
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.2.4 2022-04-15 fix #4 split .h in .h and .cpp
|
||||
// 0.2.3 2021-12-27 update library.json, license, minor edits
|
||||
// 0.2.2 2021-11-15 update Arduino-CI, readme.md badges
|
||||
// add seedMarsaglia(uint32_t a, uint32_t b)
|
||||
// fix randomDice()
|
||||
// 0.2.1 2021-01-07 Arduino-CI
|
||||
// 0.2.0 2020-07-01 rewrite.
|
||||
// 0.1.01 2015-08-18 bug fixes and further optimizations.
|
||||
// 0.1.00 2015-08-17 initial version.
|
||||
|
||||
|
||||
|
||||
#include "randomHelpers.h"
|
||||
|
@ -2,14 +2,14 @@
|
||||
//
|
||||
// FILE: randomHelpers.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.4
|
||||
// VERSION: 0.2.5
|
||||
// PURPOSE: Arduino library with helper function for faster random bits
|
||||
// URL: https://github.com/RobTillaart/randomHelpers
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define RANDOM_HELPERS_VERSION (F("0.2.4"))
|
||||
#define RANDOM_HELPERS_VERSION (F("0.2.5"))
|
||||
|
||||
|
||||
// the idea is to have one buffer ( __randomBuffer) which holds 32 random bits.
|
||||
|
@ -36,28 +36,16 @@
|
||||
#include "randomHelpers.h"
|
||||
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "RANDOM_HELPERS_VERSION: %s\n", (char *) RANDOM_HELPERS_VERSION);
|
||||
}
|
||||
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
unittest(test_new_operator)
|
||||
{
|
||||
assertEqualINF(exp(800));
|
||||
assertEqualINF(0.0/0.0);
|
||||
assertEqualINF(42);
|
||||
|
||||
assertEqualNAN(INFINITY - INFINITY);
|
||||
assertEqualNAN(0.0/0.0);
|
||||
assertEqualNAN(42);
|
||||
}
|
||||
*/
|
||||
|
||||
unittest(test_all)
|
||||
{
|
||||
@ -73,9 +61,9 @@ unittest(test_all)
|
||||
assertMore(16777215, getRandom24());
|
||||
assertMore(pow(2, 32), getRandom32());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
// --------
|
||||
|
Loading…
Reference in New Issue
Block a user