知識社群登入
位置: AutoCAD開放式教學 > 討論區 > 討論
rand1() OK
1樓
#include <cstdlib>
#include <iostream>

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

using namespace std;
// --------------------------------------------------------

int rand1(void)
{
int r1, r2;
r1= rand();
r2= rand();
return((r1<<15) + r2);
}// end of rand1()
// --------------------------------------------------------

int main(int argc, char *argv[])
{
int i, a;
a= 1<<15;// test shift left for 15 bits.
printf("\n a= %d\n\n", a);
srand( (unsigned)time( NULL ) );
// srand(123);
/* Display 10 numbers. */
for( i = 0;   i < 10;i++ )
printf( "  %12d\n", rand1() );
system("PAUSE");
    return EXIT_SUCCESS;
}// end of main()
// --------------------------------------------------------

#if 0

#endif
// --------------------------------------------------------