-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentropy.h
74 lines (66 loc) · 1.87 KB
/
entropy.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Entropy - A entropy (random number) generator for the Arduino
//
// Copyright 2014 by Walter Anderson
//
// This file is part of Entropy, an Arduino library.
// Entropy is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Entropy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Entropy. If not, see <http://www.gnu.org/licenses/>.
#ifndef Entropy_h
#define Entropy_h
#include <string.h>
#include <math.h>
// Separate the ARM Due headers we use
#ifdef ARDUINO_SAM_DUE
#include <sam.h>
#include <sam3xa/include/component/component_trng.h>
#endif
// Teensy required headers
#ifdef TEENSYDUINO
#include <util/atomic.h>
#endif
// Separate AVR headers from ARM headers
#ifdef __AVR__
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <util/atomic.h>
#endif
const uint32_t WDT_RETURN_BYTE=256;
const uint32_t WDT_RETURN_WORD=65536;
union ENTROPY_LONG_WORD
{
uint32_t int32;
uint16_t int16[2];
uint8_t int8[4];
};
class EntropyClass
{
public:
void initialize(void);
uint32_t random(void);
uint32_t random(uint32_t max);
uint32_t random(uint32_t min, uint32_t max);
uint8_t randomByte(void);
uint16_t randomWord(void);
float randomf(void);
float randomf(float max);
float randomf(float min, float max);
float rnorm(float mean, float stdDev);
uint8_t available(void);
private:
ENTROPY_LONG_WORD share_entropy;
uint32_t retVal;
uint8_t random8(void);
uint16_t random16(void);
};
extern EntropyClass Entropy;
#endif