VB icon

Random Non Repetetive Numbers

Email
Submitted on: 1/4/2015 8:12:00 AM
By: Robert Cleaver (from psc cd)  
Level: Advanced
User Rating: By 5 Users
Compatibility: C++ (general), Borland C++
Views: 798
 
     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.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Random Non Repetetive Numbers
// Description: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.
// By: Robert Cleaver (from psc cd)
//**************************************

/*
 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);
		}
	}
}


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.