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 3 7110
In article <f9************ *************@p osting.google.c om>, hu*********@yah oo.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();
longrandomnumbe r = (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/
> >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(); longrandomnumbe r = (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
Look at a http://www.math.keio.ac.jp/matumoto/emt.html it is really good.
"HUNGER" <hu*********@ya hoo.com> wrote in message
news:f9******** *************** **@posting.goog le.com... 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tom McCallum |
last post by:
Can any tell me why rand() is such a bad pseudo-random number generator.
In all the articles I have read they say that you can predict the outcome
of rand() but when I used its output with NIST's random number testsuite
it passed all of the tests thrown at it for randomness. Can anyone
suggest a test I could use that it would fail? A pointer to a suitable
article would be appreciated.
Thanks for your help in advance,
Tom
|
by: ChasW |
last post by:
given the following example:
Using gcc, this compiles, runs, and outputs as expected, but on
vc++.net 2003, the first number is always the same despite the time
seed.
#include <ctime>
#include <iostream>
using namespace std;
|
by: Chris Gordon-Smith |
last post by:
I have a simulation program that calls the rand() function at various points
while it executes.
For the user interface that displays statistics etc. while the program runs,
I use the Lazarus GUI library, which is based on GTK. Depending on which
libraries I link in, I can have either a GTK1 or GTK2 user interface.
I'm finding that the simulation behaves differently depending on whether I
link with GTK1 or GTK2.
|
by: Ben Justice |
last post by:
For a program in c, I need some random numbers for a system were people are
placing bets. This is not a commerical project btw. Generally, I tend to
rely on things from the standard library, because they're written by people
with skills far above mine. Hence, I've always used rand() and FALSELY
assumed it could produce unpredictable random numbers and could be used in
many situations even if security was an issue.
Firstly, lets assume...
|
by: Jack |
last post by:
When I use rand(), is the RAND_MAX value how long I am guaranteed that
the same value will not appear twice?
And is this a floating window?
For example, if RAND_MAX is 32767, and I make 500,000 consecutive rand
calls then is the rand() algorithm going to guarantee me that no
floating window of calls over that 500,000 rand calls will have the
same value twice? The only way that would work is if the series was
identical everytime.
| |
by: Siam |
last post by:
Hi all,
I'm writing a shell language in c++ that supports the generation of
random numbers, and by its nature, each command must be executed in a
new thread. The call to the random function from my language simply
propogates up to the rand( ) function from c++. For some reason, C++
will give each thread independent use of their own rand( ) function, so
that a rand( ) call from one thread won't affect another thread's call
to rand( )....
|
by: Gary Wessle |
last post by:
Hi
I need help to generate some random numbers between 2 and 8.
#include <cstdlib>
using std::rand;
the following was out of my range,
int main() {
|
by: Rafael Cunha de Almeida |
last post by:
Hi,
I've found several sites on google telling me that I shouldn't use
rand() % range+1
and I should, instead, use something like:
lowest+int(range*rand()/(RAND_MAX + 1.0))
|
by: remlostime |
last post by:
i use g++ to generater rand number, now i find that the RAND_MAX is
32367 in my computer, how can i make a bigger rand number( the number
is wihin in the integer(2^32-1))
|
by: Rich Fife |
last post by:
Quick rand() question:
I know you're not supposed to use "rand() % 1024" for instance,
because it focuses on the lower bits. However, it seems to me that
given that the argument is not a power of two (or near a power of
two), that this is not an issue. The upper bits will participate
equally in the result with the lower. Am I missing something?
Thanks!
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |