Arduino Forum

Topics => Education and Teaching => Topic started by: galuhboy123 on Jul 05, 2014, 06:59 am

Title: [ask] how random fungction actually work ?
Post by: galuhboy123 on Jul 05, 2014, 06:59 am
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-
:)
Title: Re: [ask] how random fungction actually work ?
Post by: Coding Badly on Jul 05, 2014, 08:50 am
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
Title: Re: [ask] how random fungction actually work ?
Post by: galuhboy123 on Jul 07, 2014, 02:05 am
thank for your support :)