Solved

Random Number Generator (>1000/sec)

Posted on 2000-04-16
3
169 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

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

730 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