Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Generating random values...

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
Xylock
Posts: 42
Joined: 2007-04-11 13:28

Generating random values...

#1 Post by Xylock »

:oops: I'm having trouble generating random values using gcc.

I've tried rand(), but it keeps giving me segmentation faults. :(

I did read that rand() is not advised in a multi-threading environment, and also somewhere else that the linux kernel could generate random numbers.

Anyone able to give me some advise on how to achieve this? This has always stumped me in C :P I dont really want to have to write my own (copy someone elses) generator, lol, I'd rather use an existing one :D
Using rm -rvf * to remove old backups... lazy.
Realising you were in / as root ... priceless.

User avatar
sinical
Posts: 1012
Joined: 2007-03-25 11:52

#2 Post by sinical »

Code: Select all

/bin/bash echo $RANDOM 
:wink:

How are you calling it in C though.. I know that something along the lines of

Code: Select all

x = rand()  %  y; 
While it does compile no errors will cause issues
Every cloud has a silver lining, except for the mushroom shaped ones, which have a lining of Strontium 90.
---------------------------------------------
umop apisdn

User avatar
Optional
Posts: 326
Joined: 2007-02-05 05:02

#3 Post by Optional »

Make sure you're seeding the random number generator by calling srand() first.

srand(time(NULL));

Post Reply