Go Down

### Topic: Numbers + Random (Read 655 times)previous topic - next topic

#### Goofballtech

##### Dec 02, 2009, 09:29 pm
So.... i have seen quite a few programs on here that do a wide variety of things in the last month or so i have been playing with the arduino and scavenging all the information i can get about kewl projects i may be interesting in putting together.

One thing i can't see the difference in is people who do the number add method instead of just typing the number.

for example, whats the difference in...

random (255);

or

random ((120) + 135);

Does it really matter? i have seen quite a few people who do this addition method but normally it seems it would be easier just to put what you want in there and continue on......i dunno maybe i'm just thick.

:-/ i'm confused.....

#### PaulS

#1
##### Dec 02, 2009, 09:43 pm
When the random function actually get invoked, the result is the same value being passed in.

The reason for not adding the numbers together in advance generally comes form the separate numbers having meaning to the author, but the resulting added number looses that significance.

For example, if I'm writing code to simulate the roll of dice, I'd be inclined to write random(6 + 6); than to write random(12); because it's more obvious (to me) that 6 has significance whereas 12 requires a moment's thought.

#### Mitch_CA

#2
##### Dec 02, 2009, 11:44 pm
To simulate the roll of the dice you'd have to write random(6) + random(6).

(Sorry, couldn't resist...)

#### PaulS

#3
##### Dec 03, 2009, 01:56 am
Of course, you're right. It was the only thing that I could think of right away. There are cases, though, where adding the numbers together obscures the meaning, and letting the Arduino add them takes very little time.

#### Goofballtech

#4
##### Dec 03, 2009, 09:25 pm
Ok. So pretty much it's for no programming significance other than to make the code easier to read if the numbers have alternate meaning to the viewer.

Thanks.....

Go Up

Please enter a valid email to subscribe