Arduino random numbers! - (Arduino Uno Programming for Beginners)

preview_player
Показать описание
Arduino random numbers! - (Arduino Uno Programming for Beginners)
In this video I show you how to generate random numbers, and not so random numbers.

0:00 intro
0:13 rand basics
1:37 deterministic random numbers
2:01 generate dice numbers
3:19 random seed
4:27 button exercise
5:00 button solution
6:10 only one number for one button press
8:14 debouncing
Рекомендации по теме
Комментарии
Автор

Nice video.
Just some additional information:
- Setting the random seed only once at the beginning is sometimes very useful, since it is easier to debug your code.
- Using millis() as seed is not good if you need very many random times, since if millis() didn't change (since the Arduino is fast), you always get the same random number
- If you need very many random numbers it is better to not always reset the seed, since that is slow.
- Don't use milllis() if you want to code security based code like generating random numbers for encrypted communication. Because for skilled coders this will be too less random. But for "normal" use case millis() is fine.
- very good that you noticed that analogRead is only 10 bits, but the seed should have more bits. I didn't thought fully about bugs, but i think a variant like
might be fine.

A nice task is always writing a small dice checker.
So for example throwing the dice 60000 and count how many times you get the 1, 2, 3, 4, 5 and 6.
And then check if each number is around 10000 shown.
Because with such an easy test you might already find bugs like setting the seed too fast and/or wrong/bad random() functions. I remember in the past guys coded the random() function by using a function that returns a float with values between 0 and 1. And while converting that float into an integer they done it wrong and by that the number 1 showed on the dice only 5000 times (instead of 10000) and the number 6 showed 15000 times (instead of 10000), because they rounded wrong.

Volker-Dirr
Автор

Nice explanation thank you so much.
i am following all your videos, can you please make a video on timer interrupts how they work, how to set time by using timer 0.

SandhyaRani-iy
welcome to shbcf.ru