RAND GENERATOR IN C++

Discussion in 'C++' started by HUNGER, Aug 15, 2003.

  1. HUNGER

    HUNGER Guest

    HI,

    I need to generate a long random number upto 4 byte width

    but my compiler is generating 2 byte int type as RAND_MAX

    i want to genetrate a rand num like 123456789 that long

    plz help me.

    thanks for helping
    HUNGER, Aug 15, 2003
    #1
    1. Advertising

  2. In article <>, (HUNGER) wrote:
    >HI,
    >
    >I need to generate a long random number upto 4 byte width
    >
    >but my compiler is generating 2 byte int type as RAND_MAX
    >
    >i want to genetrate a rand num like 123456789 that long
    >
    >plz help me.
    >
    >thanks for helping


    Something like:

    randomnumber1 = rand();
    randomnumber2 = rand();
    longrandomnumber = (randonumber1 << 16) | randonmumber2;

    Better ways to generate 4 byte randon mumber can be found on the Internet.

    Jørn Dahl-Stamnes, EDB Teamco AS
    e-mail: (remove nospam first)
    web: http://spiderman.novit.no/dahls/
    Jørn Dahl-Stamnes, Aug 15, 2003
    #2
    1. Advertising

  3. HUNGER

    Guest Guest

    > >I need to generate a long random number upto 4 byte width
    > >but my compiler is generating 2 byte int type as RAND_MAX
    > >i want to genetrate a rand num like 123456789 that long

    >
    > randomnumber1 = rand();
    > randomnumber2 = rand();
    > longrandomnumber = (randonumber1 << 16) | randonmumber2;


    I use this too, but I have something else:

    So, It is in x86 Assembly, I convert it ;-)
    --------- seed is the seed ;-) -----------
    mov eax, [seed]
    mul eax, 343fdh
    add eax, 269ec3h
    mov [seed],eax
    ---------first time random = seed-------
    random = random * 0x343fd + 0x269ec3;
    ----------------------------------------
    This is part of code which produce VC++ 6.0 compiler for 'rand()'
    I have changed this code to return 32 bit random values
    Guest, Aug 15, 2003
    #3
  4. Look at a http://www.math.keio.ac.jp/matumoto/emt.html it is really good.

    "HUNGER" <> wrote in message
    news:...
    > HI,
    >
    > I need to generate a long random number upto 4 byte width
    >
    > but my compiler is generating 2 byte int type as RAND_MAX
    >
    > i want to genetrate a rand num like 123456789 that long
    >
    > plz help me.
    >
    > thanks for helping
    Jesper Madsen, Aug 16, 2003
    #4
    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. Martin Maurer
    Replies:
    3
    Views:
    4,784
    Peter
    Apr 19, 2006
  2. TheDustbustr
    Replies:
    1
    Views:
    437
    Sami Hangaslammi
    Jul 25, 2003
  3. Replies:
    9
    Views:
    531
  4. Carl Banks

    Re: Seeding the rand() Generator

    Carl Banks, Aug 3, 2009, in forum: Python
    Replies:
    4
    Views:
    463
    Nils Ruettershoff
    Aug 6, 2009
  5. 7stud --

    rand() v. rand(0.1) ?

    7stud --, Sep 15, 2007, in forum: Ruby
    Replies:
    6
    Views:
    221
    Morton Goldberg
    Sep 16, 2007
Loading...

Share This Page