Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   newbie dll/random number questions (http://www.velocityreviews.com/forums/t315388-newbie-dll-random-number-questions.html)

Newsgroup Posting ID 09-21-2003 07:13 AM

newbie dll/random number questions
 
i'm writing a dll that generates a lot of server console output and as it
will be loaded by several server tasks at the same time the dll output from
all those tasks will be intermixed so i'd like to tag each output line with
an 'id' (generated at dll load time) to identify which lines belong together
(came from the same task).

i've tried using the system time (including milliseconds) but it's not
enough, occasionally i can see two loads that were started in the same
millisecond, i thought of adding a random number to the end to break them up
but as these are being seeded with the (same) load time they end up
generating the same random number.

is there another way i can uniquely identify them?

thanks



Thomas Stegen 09-21-2003 08:28 AM

Re: newbie dll/random number questions
 

"Newsgroup Posting ID" <newsgrouppostingid@invalid.bigpond.com> wrote in
message news:2ccbb.114915$bo1.108139@news-server.bigpond.net.au...

> is there another way i can uniquely identify them?


Have a counter?

--
Thomas.



Kevin Easton 09-21-2003 08:42 AM

Re: newbie dll/random number questions
 
Newsgroup Posting ID <newsgrouppostingid@invalid.bigpond.com> wrote:
> i'm writing a dll that generates a lot of server console output and as it
> will be loaded by several server tasks at the same time the dll output from
> all those tasks will be intermixed so i'd like to tag each output line with
> an 'id' (generated at dll load time) to identify which lines belong together
> (came from the same task).
>
> i've tried using the system time (including milliseconds) but it's not
> enough, occasionally i can see two loads that were started in the same
> millisecond, i thought of adding a random number to the end to break them up
> but as these are being seeded with the (same) load time they end up
> generating the same random number.
>
> is there another way i can uniquely identify them?


This is a question about windows, not C, I'm afraid - so you'll probably
get a better answer if you ask in a windows programming newsgroup (look
under the comp.os.* hierarchy). However many operating systems keep a
unique id per task - what about using this task / process id ?

- Kevin.


Newsgroup Posting ID 09-21-2003 11:23 AM

Re: newbie dll/random number questions
 
hi,

i can't, this is for a dll, it gets loaded by the task(s), the counter in
the dll would never increment as the dll itself is never loaded more than
once per task, (the dll code itself is loaded just once and each task that
loaded the dll gets a seperate data storage area) thats why i was looking
for a real random number generator, something i could add to the system time
to make it unique

thanks



Irrwahn Grausewitz 09-21-2003 11:36 AM

Re: newbie dll/random number questions
 
"Newsgroup Posting ID" <newsgrouppostingid@invalid.bigpond.com> wrote:

>hi,
>
>i can't, this is for a dll, it gets loaded by the task(s), the counter in
>the dll would never increment as the dll itself is never loaded more than
>once per task, (the dll code itself is loaded just once and each task that
>loaded the dll gets a seperate data storage area) thats why i was looking
>for a real random number generator, something i could add to the system time
>to make it unique
>
>thanks
>


Your question is still off-topic in c.l.c, so please refer to a more
suitable ng, like Kevin already suggested.

However: using random number generators to produce unique ids is a very
bad idea for obvious reasons: how would you guarantee that no two
instances will produce the same number at the same time by chance?

Regards

Irrwahn
--
The generation of random numbers is too important to be left to chance.

Kevin Easton 09-21-2003 02:08 PM

Re: newbie dll/random number questions
 
Newsgroup Posting ID <newsgrouppostingid@invalid.bigpond.com> wrote:
> hi,
>
> i can't, this is for a dll, it gets loaded by the task(s), the counter in
> the dll would never increment as the dll itself is never loaded more than
> once per task, (the dll code itself is loaded just once and each task that
> loaded the dll gets a seperate data storage area) thats why i was looking
> for a real random number generator, something i could add to the system time
> to make it unique


I can only assume this is in reply to my reply, since you didn't leave
any context. But I didn't say anything about a counter - I said to use
the task / process ID that your OS assigns to each task / process -
which is necessarily unique across tasks / processes. You'll have to go
ask in a Windows programming newsgroup to find out how to get this,
though.

- Kevin


Jack Klein 09-21-2003 07:08 PM

Re: newbie dll/random number questions
 
On Sun, 21 Sep 2003 07:13:02 GMT, "Newsgroup Posting ID"
<newsgrouppostingid@invalid.bigpond.com> wrote in comp.lang.c:

> i'm writing a dll that generates a lot of server console output and as it
> will be loaded by several server tasks at the same time the dll output from
> all those tasks will be intermixed so i'd like to tag each output line with
> an 'id' (generated at dll load time) to identify which lines belong together
> (came from the same task).
>
> i've tried using the system time (including milliseconds) but it's not
> enough, occasionally i can see two loads that were started in the same
> millisecond, i thought of adding a random number to the end to break them up
> but as these are being seeded with the (same) load time they end up
> generating the same random number.
>
> is there another way i can uniquely identify them?
>
> thanks


Neither C nor C++ have DLLs. DLLs are a mechanism of your operating
system, not defined or supported by either of the languages discussed
here. If you want to talk about DLLs, you need a Windows programming
group or one that supports your particular brand of Window compiler.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq


All times are GMT. The time now is 08:29 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.