Random Non Repetetive Numbers
This program fills an array[20] with random numbers between 1 and 20, without repeating a number. This code can be used for encryption, games, testing software and much much more. give me some credit if you use it, and if you like it vote.. if you change it, please send me the updated version. thanks for downloading it.
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
/*
Name: Robert Cleaver
Date: 9 - 17 - 02
Prog: RANDOM.CPP
Desc: Generates a non-repetetive random number
*/
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
typedef int itype[20];
void DoRandom(itype &RandomArr);
int check(itype &RandomArr, int ArrayIndex);
int main()
{
clrscr();
randomize();
itype RandomArr;
DoRandom(RandomArr);
getch();
return(0);
}
void DoRandom(itype &RandomArr)
{
int FillLoop;
FillLoop = 0;
RandomArr[1] = (rand() % 20) + 1;
for (FillLoop = 2; FillLoop <= 20; FillLoop++)
{
RandomArr[FillLoop] = (rand() % 20) + 1;
while (check(RandomArr,FillLoop) != 1)
{
RandomArr[FillLoop] = (rand() % 20) + 1;
}
cout<<FillLoop<<": "<<RandomArr[FillLoop]<<endl;
}
}
int check(itype &RandomArr, int ArrayIndex)
{
int CheckLoop, nomatch;
nomatch = 0;
CheckLoop = 0;
for (CheckLoop = 1; CheckLoop < ArrayIndex; CheckLoop++)
{
if (RandomArr[CheckLoop] == RandomArr[ArrayIndex])
{
nomatch = 1;
return(0);
}
else if (CheckLoop == (ArrayIndex - 1) && nomatch == 0)
{
return(1);
}
}
}
Original Comments (3)
Recovered from Wayback Machine