I'm in the VC environment using C + + to write the algorithm when you want to achieve with the function RANDOM random, but said he did not define this function

Category: C/C++ -> C Author: huanjlk Date: 2004-05-26 15:57:50
 
huanjlk
2004-05-26 15:57:50
I'm in the VC environment using C + + to write the algorithm when you want to achieve with the function RANDOM random, but said no this function is not defined, Will you have not encountered such a situation, how to solve?
lmsreg01
2004-05-26 16:08:50
seed value, then use the srand / * RAND.C: This program seeds the random-number generator
* with the time, then displays 10 random integers.
* /

# include <stdlib.h>
# include <stdio.h>
# include <time.h>

void main (void)
{
int i;

/ * Seed the random-number generator with current time so that
* ; the numbers will be different every time we run.
* /
srand ((unsigned) time (NULL));

/ * Display 10 numbers. * /
for (i = 0; i <10; i + +)
printf ( "% 6d \ n", rand ());
}
zx200585
2004-05-26 16:21:38
<cstdlib>

int ; rand (void);
0 to AND_MAX it generates a pseudo-random number sequence.
with srand () to initialize the random seed.
gy0801256
2004-05-26 16:28:26


void RND (int n0, int n, int m, int * rn)) ;/ * generation random from n0-n, total m, put to rn * /

{
int tmp;
srand ((unsigned) time (NULL));
for (int i = 0; i <m; i + +)
{
tmp = rand ()% (n-n0) + n0;
rn [i] = tmp;
}
}

lovelycheep
2004-05-26 16:32:08
I remember out of the rand is a random number between 0-1, rand () * 50 range is 1-50 in the

if not 0 -1, then as long as rand ()% 50 +1, the range is 1-50 lah!
teresalh
2004-05-26 16:37:32
is RAND_MAX
dzzjr
2004-05-26 16:48:21
This example is not a C / C + + Programmer's Manual on you?
My problem is that there is no RANDOM function,

you use RAND his range is 0 --------- 0F7FFF

it still alluding ah?

RANDOM comes with a range of functions can decide not it be nice?
have used no?
wkyflyingship
2004-05-26 17:06:10
void main (void)
{
int i;

/ * Seed the random-number generator with current time so that
* the numbers will be different every time ; we run.
* /
srand ((unsigned) time (NULL));

/ * Display 10 numbers. * /
for (i = 0; i <10; i + +)
printf ("% 6d \ n", rand ());
}

Output

6929
8026
21987
30734
20587
6699
22034
25051
7988
10104

was earlier than I used MSDN, I have points.
bitfinalwork
2004-05-26 17:12:33
No, I can not find out the msdn inside, I can give you compile a. That this is not there yet?
gongjia15879485996
2004-05-26 17:17:14
I want a number ranging from 1 ----- 50 how to solve?
lielielie
2004-05-26 17:21:04
still own it msdn there are not mapping function that
remainder except 51 bar
haiboxie
2004-05-26 17:39:29
Strange, I bought the book Conservancy Press said there RANDOM This function ah?
ina131492010
2004-05-26 17:57:50
I checked the C function Guinness, no RANDROM (), C + + do not know.
(50 * rand () / RAND_MAX) +1
sun781234
2004-05-26 18:01:27
# include <iostream>
# include <cstdlib>
# include <ctime>

using namespace std;

int main ()
{
int h [10000];
int read [51] = {0} ;
srand (time (NULL));

for (int i = 0; i <10000; i + +)
{
h [i] = (50 * rand ( ) / RAND_MAX) +1;
+ + read [h [i]];
}
for ( i = 0; i <51; i + +)
{
cout << "The number of "<< i <<" is: "<< read [i] << endl;
}
system ("PAUSE");
return 0;
}
dsys88
2004-05-26 18:17:27
Water Conservancy Press book ; is about vc under the program do?
tc does have this function under the
celine_0
2004-05-26 18:23:19
MSDN April 2002 edition can be found ah
fys963
2004-05-26 18:35:48
Thank you to the sub less

the point, sorry
SimpleSeven
2004-05-26 18:53:58
Re people: joe_fox1025 (joe_fox) () Reputation: 1002003-03-12 13:06:00 score : 0

Thank you

to the sub just does not, sorry

What does this mean? ?