LinuxQuestions.org
Have you listened to LQ Radio?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Tags used in this thread
Popular LQ Tags , ,

Reply
 
Thread Tools
Old 11-05-2009, 09:52 PM   #16
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 1,637
Thanked: 18

[Log in to get rid of this advertisement]
640K is enough for anybody.
linux tuxdev is online now     Reply With Quote


Thanked by:
Old 11-06-2009, 01:53 AM   #17
bartonski
Member
 
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora Core, Slackware, Debian, Ubuntu Jaunty
Posts: 251
Thanked: 8
Quote:
Originally Posted by smeezekitty View Post
how can you even call a program 1000000 times per second?
bash, batch and C system and exec calls are all too slow.
the only way you could do it is if its from withen it self and in that case it would have the same PID.
If you XOR the PID, you don't have to use that type of time resolution.

I can't tell you why, but I like

Code:
seed ( getpid() ^ time() );
better than

Code:
seed( tv_sec * tv_usec (microseconds));
Moore's law ought to knock about 3 orders of magnitude off your safety factor there in 10 years, or 6 in 20. The first line of code will work just as well then as now. The second? I'll take your bet that I can't launch processes that fast in 10 years.
linuxubuntu bartonski is offline     Reply With Quote


Old 11-06-2009, 03:31 AM   #18
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 11
Posts: 1,860
Thanked: 26
Having looked through the thread it would appear that the answer I was going to give to the original problem has already been given by Johnsfine.

However, the digression on how you seed the random numbers raises a few thoughts. To me I don't like the idea of using the PID because first it is not cross platform. I also like to keep a record of the seed so that the process can be recreated so I tend not to use time() either rather a variable that could be read in or derived (possibly from the time function). But basically if having "random numbers" is a critical element of a program then don't use the rand function but look for a means of getting true random numbers.
linuxfedora graemef is offline     Reply With Quote


Thanked by:
Old 11-06-2009, 03:39 AM   #19
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 8.04 (upgraded from 6.06), Ubuntu Netbook Remix 9.04
Posts: 2,742
Thanked: 87
Quote:
Having looked through the thread it would appear that the answer I was going to give to the original problem has already been given by Johnsfine.
johnsfine was a little late This thread was started 4 years ago
windows_xp_2003 Wim Sturkenboom is offline     Reply With Quote


Old 11-06-2009, 08:48 AM   #20
johnsfine
Senior Member
 
Registered: Dec 2007
Posts: 1,687
Thanked: 182
Quote:
Originally Posted by Wim Sturkenboom View Post
johnsfine was a little late This thread was started 4 years ago
Oops!

I didn't notice the fact that the thread was reopened with a different question, nor the dates on the earlier posts. I just saw that there seemed to be no answer posted for the original question.

I really wish the forum software would give some very visible indication when there is a giant jump in date between two successive posts in a thread.
windows_xp_2003 johnsfine is offline     Reply With Quote



Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
code for generating random samples! aru_04 Programming 2 07-21-2005 09:35 AM
Generating Gaussian Random Numbers R00ts Programming 2 08-11-2004 12:51 AM
Creating random numbers from shell with /dev/random khermans Linux - General 1 07-13-2004 01:12 PM
Generating random numbers for C program J-Stew Programming 14 02-06-2004 05:49 AM
Random numbers in C loke137 Programming 7 03-07-2003 05:56 PM


All times are GMT -5. The time now is 12:48 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration