By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,436 Members | 2,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,436 IT Pros & Developers. It's quick & easy.

RAND GENERATOR IN C++

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <f9*************************@posting.google.com> , hu*********@yahoo.com (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: Jo***************@nospam.novit.no (remove nospam first)
web: http://spiderman.novit.no/dahls/
Jul 19 '05 #2

P: n/a
> >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
Jul 19 '05 #3

P: n/a
Look at a http://www.math.keio.ac.jp/matumoto/emt.html it is really good.

"HUNGER" <hu*********@yahoo.com> wrote in message
news:f9*************************@posting.google.co m...
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

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.