Devices & Components
Arduino Nano
Software & Tools
Arduino IDE
Project description
Code
random number generator code
c_cpp
upload this to the arduino and open a serial monitor or plotter.
1long randomnum; //creates the variable randomnum 2int floatingpin = 0; //creates the variable floatingpin 3const int emptypin = A1; //put an unused analog pin in here 4void setup() { 5 Serial.begin(9600); //initialises the serial port 6 randomSeed(23); //put any number in here 7 pinMode(emptypin, INPUT); //sets emptypin as an input 8} 9void loop() { 10 floatingpin = analogRead(emptypin); //sets floating pin to the value of the empty pin 11 randomnum = random(2,176); //put a low number and a high number in here, they are the variables that set the parameters of the randomness. 12 Serial.println(randomnum); //prints out the number 13 randomSeed(randomnum/(randomnum*(randomnum*floatingpin))); //sets the seed to a comletely random number 14 delay(randomnum); //waits for how long the random number is 15 16} 17
Downloadable files
untitled
untitled

untitled
untitled

Comments
Only logged in users can leave comments