Go Down

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

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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy