void setup() {
Serial.begin(9600);
// Seed our random number generator
randomSeed(analogRead(A0));
}
void loop() {
String str;
int num;
// Ask the user to enter the number of sides on the die
Serial.println("Enter the number of sides on the die");
while ( str.equals("") ) {
str = Serial.readString();
}
// Convert input string into a number
num = str.toInt();
// Only roll the die if we have a positive number
if ( num > 0 ) {
num = random(1, num + 1);
Serial.print("You rolled: ");
Serial.println(num);
}
}
Simulator: https://tinkercad.com/things/0zACluQ1s2r