newbie dll/random number questions

Discussion in 'C Programming' started by Newsgroup Posting ID, Sep 21, 2003.

  1. 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
    Newsgroup Posting ID, Sep 21, 2003
    #1
    1. Advertising

  2. "Newsgroup Posting ID" <> wrote in
    message news:2ccbb.114915$...

    > is there another way i can uniquely identify them?


    Have a counter?

    --
    Thomas.
    Thomas Stegen, Sep 21, 2003
    #2
    1. Advertising

  3. Newsgroup Posting ID

    Kevin Easton Guest

    Newsgroup Posting ID <> 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.
    Kevin Easton, Sep 21, 2003
    #3
  4. 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
    Newsgroup Posting ID, Sep 21, 2003
    #4
  5. "Newsgroup Posting ID" <> 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.
    Irrwahn Grausewitz, Sep 21, 2003
    #5
  6. Newsgroup Posting ID

    Kevin Easton Guest

    Newsgroup Posting ID <> 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
    Kevin Easton, Sep 21, 2003
    #6
  7. Newsgroup Posting ID

    Jack Klein Guest

    On Sun, 21 Sep 2003 07:13:02 GMT, "Newsgroup Posting ID"
    <> 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
    Jack Klein, Sep 21, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. xeys_00
    Replies:
    12
    Views:
    853
    Jonathan Arnold
    Apr 11, 2005
  2. ilias
    Replies:
    5
    Views:
    387
    Pete Becker
    Jul 27, 2006
  3. globalrev
    Replies:
    4
    Views:
    757
    Gabriel Genellina
    Apr 20, 2008
  4. Alex Untitled
    Replies:
    11
    Views:
    659
    Giampiero Zanchi
    Nov 16, 2009
  5. VK
    Replies:
    15
    Views:
    1,161
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page