LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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


Reply
  Search this Thread
Old 05-14-2005, 08:39 PM   #1
deveraux83
Member
 
Registered: Jul 2003
Location: Malaysia
Distribution: Red Hat, Slackware 9.1
Posts: 76

Rep: Reputation: 15
random numbers


Hey guys,

Just wanted to ask some questions about random number generators in C++, specifically those using the functions:
initstate(), setstate(), srandom() and random().

Can anyone explain what exactly does the char *state in both initstate and setstate do? I have tried altering the values of state when I call initstate but the the output remains the same. I thought, from the man pages, that state points to an array used by the random number generator and hence should effect it quite significantly.

Thanks for your time.
 
Old 05-16-2005, 11:15 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
char *state is a state table. You will change things only AFTER you start calling random().

The state table is set to an initial value, and subsequent calls to random() reset it to new values.

I hope you don't plan to mess with the state table, it is not going to help anything. In fact it could do the reverse.
 
Old 05-16-2005, 12:23 PM   #3
deveraux83
Member
 
Registered: Jul 2003
Location: Malaysia
Distribution: Red Hat, Slackware 9.1
Posts: 76

Original Poster
Rep: Reputation: 15
That's what I did. I called random() AFTER I called initstate() with a char *state of my own. And it didn't generate a different number pattern than if I just left it at it's default value. (i.e. the sequence of numbers is exactly the same).

What I am hoping to do is make the random number generator more "configurable" since I need it for an encryption sequence I am creating. Do you know of any sites that might explain what the state table is since I didn't get any good hits on google.

Thanks for your reply.
 
Old 05-16-2005, 12:27 PM   #4
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
No. I'm not clear. Mess with the state table AFTER random() has been called at least once.
 
Old 05-17-2005, 02:26 AM   #5
deveraux83
Member
 
Registered: Jul 2003
Location: Malaysia
Distribution: Red Hat, Slackware 9.1
Posts: 76

Original Poster
Rep: Reputation: 15
Oh ok. I get your point now. I will try that. Thanks!
 
  


Reply



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
generating random numbers in C abk4523 Programming 20 01-10-2011 04:08 PM
Random numbers in C loke137 Programming 9 09-11-2010 10:37 AM
random numbers deveraux83 Programming 2 02-28-2005 05:36 PM
Generating Gaussian Random Numbers R00ts Programming 2 08-10-2004 11:51 PM
Creating random numbers from shell with /dev/random khermans Linux - General 1 07-13-2004 12:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:46 AM.

Main Menu
Advertisement
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
Twitter: @linuxquestions
Open Source Consulting | Domain Registration