Solved

Random Number Generator (>1000/sec)

Posted on 2000-04-16
3
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
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.

690 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