Math functions like random and sin

Sometimes you need a random number.

Strange enough: this math function is  found in the stdlib.h: rand() with datatype int

Other math functions are found in the math.h:

like abs, cos, sin, tan, atan

you use the libs like this:




int main(){

printf( “this is a random number between 0 and 10 %d \n”, rand() % 10 );

printf( “this is a sin %f \n”, sin(.157) );

while(1) {}


Also in the makefile -lm should be added, if it isn’t. You get funny bugs if it isn’t.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: