Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

Random Number Generator (>1000/sec)

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
philipw
Asked:
philipw
  • 2
1 Solution
 
laeuchliCommented:
You only have to seed it once with time, after that you can continue to call rand and get a random number.
0
 
philipwAuthor Commented:
Thanks for your quick help

I guess I should have known that!
0
 
laeuchliCommented:
I had the problem to :-). Glad I could help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now