Hi Mikal, I read the thread on the forum that you posted.
Most of the avr-libc library is written in hand optimized assembly, so they are not compiled. However there are a few functions that are implemented in C and are compiled, which means that they can be affected by any issues in the compiler. The random functions are part of the few functions that are implemented in C. Note that you should always seed the function first, before using it. It is a bit odd that the random function is working on Windows, but not on Linux. This points to a potential issue with AVR GCC compiler on the particular Linux distribution. From reading the arduino forum thread, it sounds like the compiler that is being used is 4.3.0, correct? There are known compiler generation issues with that version, unless the AVR GCC distribution on Linux is using the patches that are included in the WinAVR distribution. Can you find out this information?: - Which Linux distribution does the problem show up on? - Who is the maintainer of the AVR GCC toolchain on that Linux distribution? - Which version of AVR GCC is being built? (Is it 4.3.0?) - How is the AVR GCC toolchain being built? What patches are being used? What is the configuration command line? As an extra note to the AVR GCC toolchain maintainer for whatever Linux distribution: it is better to use gcc 4.3.2 (the latest release) as it contains the bug fixes for the code generation problems that exist in 4.3.0. Also, for avr-libc bug reports, there is a bug list at the avr-libc project on Savannah: <http://savannah.nongnu.org/projects/avr-libc> It is better to submit a bug report so it gets saved in the bug database. Emails on a mailing list get lost very quickly. HTH, Eric Weddington > -----Original Message----- > From: > avr-libc-dev-bounces+eweddington=cso.atmel....@nongnu.org > [mailto:avr-libc-dev-bounces+eweddington=cso.atmel....@nongnu. > org] On Behalf Of Mikal Hart > Sent: Saturday, January 03, 2009 2:30 PM > To: AVR-libc-dev@nongnu.org > Subject: [avr-libc-dev] bug in rand()/random()/do_rand()/do_random( ) > > Hi all-- > > > > I hope I'm posting to the correct spot here. > > > > We over in the Arduino development community (http://www.arduino.cc > <http://www.arduino.cc/> ) have observed what seems to be a bug in > avr-libc's random() and rand() (but only in Linux builds). > > > > For example, if you run a little Arduino sketch (btw, Arduino uses the > AVR-168P) that calls random() nine times (without seeding), > you immedately > get a repeat in your series: > > > > 0 31031784 26852320 4242000 842292 453960 211932 84160 0 ... > and so on (!) > > > > As you can see, these are not very random. :) This example > was generated > from an Ubuntu host. Developers who use Windows don't seem > to be affected. > The random() and rand() sequences with Windows are entirely > reasonable. > > > > For more details, please see this thread: > http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1227218077/45. > > > > Thanks! Is there somewhere else that I should post bug > reports like this? > > > > Mikal Hart > > Intel Corporation > > > > _______________________________________________ > AVR-libc-dev mailing list > AVR-libc-dev@nongnu.org > http://lists.nongnu.org/mailman/listinfo/avr-libc-dev > _______________________________________________ AVR-libc-dev mailing list AVR-libc-dev@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-libc-dev