Perfect acquisition of random numbers

Source: Internet
Author: User

/****************************

To verify the accuracy, remove the commented out part

****************************/



#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUMB1 15
#define NUMB2 5
/****************************
NUMB1: Determine how many consecutive random numbers to generate
NUMB2: Panning the range of random numbers
****************************/
int main () {
int f = 0;

int cq=1000;

int C[NUMB1] = {0}; /** is used to verify that a random number exists and is initialized to 0 **/


int CNT[NUMB1] = {0}; /** take out the random number **/


int count = 0; /** is used to ensure that the program ends when it is finished **/

Srand (Time (NULL));/** Temporal seed **/
while (cq--) {

while (1)
{
int r = rand ()%NUMB1; /** produces a numb1 random number, ranging from 0 to numb1-1**/

if (++c[r] > 1)/** If there is already a random number and the number of the array is the same, the number is reset **/
Continue
Else
{
Cnt[count] = r + numb2; /**CNT an order fetch number
Numb determine the amplitude, or the angle of the translation
**/



printf ("%2d", Cnt[count]); /**, starting from scratch **/

if (++count >= numb1)/** 1<+>1**/

Break
}
// }

/** count = 0;
printf ("\ n");
for (f = 0;f<numb1;f++) {
c[f]=0;
}**/
}

return 0;
}

Perfect acquisition of random numbers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.