Pages: [1]   Go Down
Author Topic: Random function  (Read 1348 times)
0 Members and 1 Guest are viewing this topic.
malmö / berlin
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
fhp>--vs--<k3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Hej,

I'm surging for a random function for Arduino;

I know I can get a pseudo-random number if I read one of the analog-Inputs I'm not using, but this just work if something happened there, like: touching the input, otherwise I get always a very similar number.

So at the end I need a random number between 1 and 720, maybe someone have a nice idea?

Thanks a lot.
tomek
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
Dont think like a computer, make it think like you
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I need this too...

Anything?

Gabe
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
Dont think like a computer, make it think like you
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually it's just

rand()

It appears to be 16 bit... (I never got a number > 32334, so I'm guessing)


Gabe
Logged

Britanny
Offline Offline
Full Member
***
Karma: 0
Posts: 233
Mais vrai, j'ai trop pleuré, toute lune est atroce
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hy

for a random : read an analog input with nothing plug on.
for more info do a search, we answer few week ago to this question smiley-wink
here : http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1145117943/ :-[

regards

eric
Logged

malmö / berlin
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
fhp>--vs--<k3
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

yes, yes we know you can use a analog input, but i think this is not the "nice" way, isn't it that this radom number get influrenced by the analog input, futhermore by the surrounding of the input, room temperature etc.

it seems to produces alway the same numbers, after a file i get some numbers which looks like random, but i'm not so shure about this,....

would be nice to have a real random funktion,...

hej då,
tomek
Logged

Britanny
Offline Offline
Full Member
***
Karma: 0
Posts: 233
Mais vrai, j'ai trop pleuré, toute lune est atroce
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

 ;D
what is a "real" random function without floating point variables ?

from the reference manual :
Quote
Variables .... Warning: floating point variables and operations are not currently supported.

char
int
long

try something with millis() !

AnalogRead return a value betwen 0 and 1024...
for my point of view, random function is not the most important thing to implement in Arduino.

with my friend Google i've found a pseudo random for VB6... can it help ?
Code:
Const xA = 16598013
 Const xC = 12820163
 Const xM = 16777216
 Const xI = 602453
 Dim Seed As Long
 
 Private Sub Form_Load()
     Seed = 327680
 End Sub
 
 'simule la Fonction Rnd()
 Private Function Random() As Single
     Dim s As Long
     Dim x As Currency
     x = CCur(xA) * Seed + xC
     Seed = x - Int(x / xM) * xM
     Random = Seed / xM
 End Function

Quote
CCur :
 Converts expression to a Currency. CCur accepts any numeric or string data that
can be expressed as a currency value. The function recognizes the decimal and
thousands separators based on locale information on the client computer.
....
Quote
The Currency data type is actually an integer type internally. In use, it is scaled by a factor of 10,000 to give four digits to the right of the decimal point. It permits up to 15 digits to the left of the decimal point, resulting in a range of approximately -922,337,000,000,000 to +922,337,000,000,000. An individual type Currency variable takes up 8 bytes of memory, compared to 4 bytes for Single.

regards
eric
« Last Edit: May 15, 2006, 08:56:39 pm by mrbbp » Logged

Pages: [1]   Go Up
Jump to: