Solved

Random Number Generator (>1000/sec)

Posted on 2000-04-16
3
165 Views
Last Modified: 2010-04-02
Hi all,

I need to generate a lot (>1000/sec) of random numbers in a short space of time.  The random number generator I've used in the pased (see below) uses time as the seed.  This works fine if you are generating less then one per sec but I need more than that. When I use the function I get the same 3 numbers for a second and once the clocks second changes I get another 3 numbers.  I'm using Borland C++.


#include <time.h>
int rand_num;
int Get_rand()
{
   time_t t;
   srand((unsigned) time(&t));
   do
   {
       rand_num = rand() % 11;
   }
   while (rand_num < 1)
return rand_num;
}


Thanks in advance.

Phil
0
Comment
Question by:philipw
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
laeuchli earned 100 total points
ID: 2721269
You only have to seed it once with time, after that you can continue to call rand and get a random number.
0
 

Author Comment

by:philipw
ID: 2721292
Thanks for your quick help

I guess I should have known that!
0
 
LVL 5

Expert Comment

by:laeuchli
ID: 2721296
I had the problem to :-). Glad I could help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now