Writing a Random Number Generator?

dmw16

Diamond Member
Nov 12, 2000
7,608
0
0
I was wondering how one would go about writing a random number generator? What language would one use? What I want is some code to run within a program so when I start the program it will prompt for a domain and also how many numbers I want generated. Is this possible? If so, how?
thanks,
-doug
 

yata

Senior member
Jun 2, 2000
746
0
0
The compilers have access to the hardware. In C or C++, function call "rand" will generate a random decimal between 0 and 1. It's based on your computer clock crystal, getting a number while the crystal oscillates. Check a primer of your compiler or a tutorial book on how to generate one.
 

CuriousMike

Diamond Member
Feb 22, 2001
3,044
543
136
Are you looking to write your own random number generator, or simply use one provided in a library?

If you're looking to write your own random number generator, I would suggest searching on the web for various topics on this difficult topic.

If you simply want to use a library version, then the documentation for your language (and/or compiler) should have full syntax for their random number generator.
 

esung

Golden Member
Oct 13, 1999
1,063
0
0
those stock RNG funcions provide by the compiler were fairly weak. I know quite a few people were either writing their own, or use other libraries that provide RNG functions.


 

juiio

Golden Member
Feb 28, 2000
1,433
4
81
Probably enough for your needs:

When your program starts, seed the random number generator with the current time. Call rand as needed.
 

Delusion2001

Banned
Feb 13, 2001
1,370
0
0
this will generate a random number in VB

--

Private Sub Command1_Click()
Minr=45
Maxr=12000
randno=minr + Fix(Rnd *(maxr-minr+1))
MsgBox randno
End Sub

--

hope it works
 

shadowfaX

Senior member
Dec 22, 2000
893
0
0
Hm... I wrote a Random Number Gen. in normal, ugly BASIC (yes, my first programming lessons). Gross... BASIC is very, very yucky.
 

brazil

Junior Member
Jan 24, 2001
14
0
0
In the book "Numerical Recipes" (http://www.nr.com) you can find many random numbers generators algorithms. There're C++, Pascal and Fortran versions of this book.
 

DJ_D

Member
Oct 11, 1999
193
0
0
Here is how you use the random number generator from the standard C library.

Seed the generator. Do this at the begining of your program.

srand(time(NULL));

Then you can call rand() which will return an integer between 0 and RAND_MAX. (RAND_MAX is usually 32,767) To get a random number between 0 and X just take the mod of X+1.

i.e. to get a random number between 0 and 99:
num = rand() % 100;

rand() does not get a random number from the computer crystal. rand() takes a seed number and produces a pseudo-random number. The next time rand() is called it uses the previously generated number as a seed. At the begining of the program you seed the generator with the time, because if you seeded with a constant number like 1, you would get the same sequence of numbers every time. The time will be different every time you run the program, so your sequence will be different.

 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |