Go Down

Topic: [ask] how random fungction actually work ? (Read 2 times) previous topic - next topic

galuhboy123

hai guys. im new in arduino so please forgive if i have something wrong while i post it :)
so the real probelm:

im just want to know how actually "random function" on arduino work .? how it can randomly choose something ? (example we set "random(1,9)" and it can randomly choose number from 1 - 9) anyone please explain the random function?

thx for your support
-galuh boy-
:)

Coding Badly

#1
Jul 05, 2014, 08:50 am Last Edit: Jul 05, 2014, 10:43 am by Coding Badly Reason: 1
Quote
im just want to know how actually "random function" on arduino work .?


https://www.google.com/search?q=pseudo+random+number+generator

https://www.google.com/search?q=minimal+standard+random+number+generator

Quote
how it can randomly choose something ?


It can't.  The function gives the appearance of being random.  For most applications that is good enough.

Quote
(example we set "random(1,9)" and it can randomly choose number from 1 - 9)


One to eight.  The maximum value is exclusive...
http://arduino.cc/en/reference/random

The Arduino random functions are simple functions layered on top of the Libc random function.  Values are mapped from 0 to RAND_MAX using modulus...
https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/WMath.cpp#L29


Go Up