Re: random number generator
Read my posts and links in them in thread Shuffle algorithm
Some bugs.
When you call srand() with identical parameters, you get identical random number sequences, so if you call srand(time(0)) every time you generate random sequence, you get the same result during the second. There generally is no point in calling srand() more then once.
You algorithms's average execution time is O(n^2).
Don't use rand()%n for large n.
Quote:
Originally Posted by thre3dee
Code:
int i = 0;
for (; ++i < nArraySize;) intArray[i] = -1;
Note that it doesn't fill intArray[0]
Quote:
Originally Posted by thre3dee
Code:
int list[20];
int_fillrand (list, 1, 20);
Even in C it's better to use OOP. You would bump in all kinds of problems if system is complex enough.
Re: random number generator
hey do you guys know anyway to get a thread (say thread 3) and tell it to stop what it's doing and start a different thread?
like
Code:
restart(3,&attr,some_function());
I have n threads, i need n-1 of them to write to a globabl variable "buffer", and everytime one of them writes to buffer, thread n has to read buffer. How can I synchronize them?
Re: random number generator
Are you sure you posted the question in the right thread?
Draw the timeline. Mark points of starting and ending of different operations on resource. Note the dependancies between them. Point 1: resourse can't be accessed (for reading or writing) by more then one thread. So, enclose the access in mutex. Point 2: reading thread should wait for writing thread to make write access. Just wake it up within brackets of mutex at any time while writing.
Re: random number generator
Quote:
Originally Posted by RoboTact
Are you sure you posted the question in the right thread?
Draw the timeline. Mark points of starting and ending of different operations on resource. Note the dependancies between them. Point 1: resourse can't be accessed (for reading or writing) by more then one thread. So, enclose the access in mutex. Point 2: reading thread should wait for writing thread to make write access. Just wake it up within brackets of mutex at any time while writing.
ya you're right, I'll delete the last post I made and put it in a new thread