/*
Seed generator for random function using generic hardware.
The RF 433 receiver captures any noise in its reception range,
We can use these pulses to generate a random number.
by Rtek1000 (06-jun-2022)
Hardware:
1- RF 433 recetor
1- Analog input
1- Resistor 10k (between receiver output and analog input)
*/
#define no_hardware_test 1 // Uncomment to test: Read input and seed in random
#define adc_test 1 // Uncomment to test: Show process data
#ifdef adc_test
byte buff[10]; // Used for sampling only, can rule out
#endif
void setup() {
// put your setup code here, to run once:
delay(300);
Serial.begin(115200);
Serial.println("Start");
#ifndef no_hardware_test
pinMode(A7, INPUT);
uint32_t val_sum = 0;
uint32_t val_time1 = 0;
uint32_t val_time2 = 0;
uint32_t timeout = 0;
for (int i = 0; i < 10; i++) {
val_time1 = micros();
timeout = 0;
while ((analogRead(A7) > 512) || (timeout < 1000)) {
delayMicroseconds(1);
timeout++;
}
timeout = 0;
while ((analogRead(A7) < 512) || (timeout < 1000)) {
delayMicroseconds(1);
timeout++;
}
val_time2 = micros() - val_time1;
val_sum += val_time2;
#ifdef adc_test
buff[i] = val_time2 & 0xFF;
#endif
}
val_sum /= 10;
#ifdef adc_test
for (int i = 0; i < 10; i++) {
Serial.print("buff(");
Serial.print(i, DEC);
Serial.print("): ");
Serial.println(buff[i]);
delay(5);
}
#endif
randomSeed(val_sum);
Serial.print("val_sum: ");
Serial.println(val_sum);
#endif
Serial.print("random: ");
Serial.println(random(0, 100));
}
void loop() {
// put your main code here, to run repeatedly:
}
The truth is there is very little "noise" at 433 mHz. What is happening is the noise generated by the IC, itself. Certainly no received noise will get through the processing of the IC. Any diode could be used for the same thing. I have a noise generator, built many years ago that does exactly that,
This receiver has no LC tank circuit. This one works with a quartz crystal. Mine is similar to this one:
The RFRM4302-RXN3S is a miniature receiver module that receives On-off keyed (OOK) modulation signal and demodulated to digital signal for the next decoder stage. Local oscillator is made of PLL structure. The result is excellent performance in a simple to use,
with a very low external component count.
Then you have a cheap noise generator, it's what the OP wants. How much RF noise, well of course it depends on what RF sources are around, on the frequency of interest. I recently noticed, I can point an antenna skyward and hear sky noise, point at the ground and it goes away. 1296MHz.
Some bands are a lot dirtier than others, I'm sure you know. Sample around 150MHz in any urban environment, it's insane.
Actually, to use it for randomness it would be better to not receive RF because the signals are not random. For example, when a wireless thermometer or such transmits, it sends a long string of regular training pulses that would be cleanly demodulated and put the kybosh on any concept of randomness. Edit - just noticed this was already mentioned in reply #5.
I'm not sure if it would always be cheaper. Consider the cost even of the proto board that you would build it on. The complete receiver is about the same price as that. It also has the analog to digital conversion on board - the "data slicer" mentioned above.
Also, in this case it's free, since the OP says " I already had the RF 433 receiver". Should probably terminate the input though, instead of attaching an antenna or leaving it open.