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. Advertisements

  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. Advertisements

  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. Advertisements

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. Niko D. Barli

    rand function in Modelsim 5.7c

    Niko D. Barli, Aug 26, 2004, in forum: VHDL
    Replies:
    9
    Views:
    6,822
    Niko D. Barli
    Sep 6, 2004
  2. Martin Maurer
    Replies:
    3
    Views:
    5,952
    Peter
    Apr 19, 2006
  3. TheDustbustr
    Replies:
    1
    Views:
    638
    Sami Hangaslammi
    Jul 25, 2003
  4. Replies:
    9
    Views:
    864
  5. Chris Withers

    Problems with email.Generator.Generator

    Chris Withers, Sep 11, 2006, in forum: Python
    Replies:
    20
    Views:
    2,090
    Max M
    Sep 12, 2006
  6. Terry Reedy

    Generator functions subclass generator?

    Terry Reedy, Jun 18, 2009, in forum: Python
    Replies:
    0
    Views:
    629
    Terry Reedy
    Jun 18, 2009
  7. Carl Banks

    Re: Seeding the rand() Generator

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

    rand() v. rand(0.1) ?

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