standard libs

Go To Last Post
9 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok this would seem easy and I got 2 pc's set up the same and 1 takes the other don;t

FIrst problem. I want to use pow

so include

and go pow(1,2)

1 pc compiles other does not and says no pow functions

2nd problem. Random numbers.

It compiles with

and I go:

random_value = rand();

it runs but gives me the same number over again.

Not sure what i am missing on this.

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

also tried setting the seed
srand(256);
before calling rand and notta

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use a timestamp, /dev/random or /dev/urandom to get entropy. Setting a static value will of course give you the exact same results each time ;)

Hans-Christian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

you completely lost me there.

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah, sorry, missed that you are running standalone.

For question 1; try adding "-lm" to the linking stage of your application, this will tell the linker to add libm (math library).

Question 2; you need a "random" seed to the rand() call, using the timestamp or similar is a very easy way to get half good entropy.

Hans-Christian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

humm. i think i understand what your saying.

Could you post a random example.

I need 8 bit number from 0x01 to 0xFF.

seed being srand(anynumber) i think right?

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also spoke with atmel today, and it seems in some cases cygwin does not path right in envirment variables, so that is something I will check again on my math.h

Like I said 1 pc it compiles, other does not, and did same installs so maybe it is the path.

Like I said atmel seen this happen many times.

Good to know its not me going batty.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

FYI:

I added -lm in linker command line and that solved the trick. Also make sure you path environment has cygwin included. Atmel rep told me sometimes the install does not do that.

here is the new command line:

avr32-gcc-lm

All good now....

Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

also I used cpu clock ticks from the included cpu.h from framworks to seed my rand.

i = get_sys_count()); 
srand(i)// set the seed
i = rand(); // Pull random number 

Mike