BballJosh
March 4th, 2009, 06:38 PM
I am trying to display a list of words in random order. To do this I am generating a random number and then checking it against an array to see if the number has been used already. I am basically self taught so things may be inefficient/not the correct way to do things, but it works and that's all I really care about. So anyways, when I execute this code:
int number = Words->Length;
System::Random^ RandNumber = gcnew System::Random();
int RandNum = RandNumber->Next(0,number);
//Check to make sure word has not been used yet
if(CheckNum->Length==Words->Length)
CheckNum->Clear;
for(int c=0;c<Words->Length;c++)
{
if(CheckNum[c]==RandNum)
{
RandNum = RandNumber->Next(0,number);
c=0;
}
}
int CheckInt = CheckNum->Length;
CheckNum[CheckInt] = RandNum;
I get the error: Object reference not set to an instance of an object. I'm not sure what I'm doing wrong. Any ideas? And I should probably define variables up top I know but I just add them when I need them when I'm troubleshooting, I can clean it up later. Oh and CheckNum is defined higher up in the code as: array<int^>^CheckNum;
Thanks for the help
int number = Words->Length;
System::Random^ RandNumber = gcnew System::Random();
int RandNum = RandNumber->Next(0,number);
//Check to make sure word has not been used yet
if(CheckNum->Length==Words->Length)
CheckNum->Clear;
for(int c=0;c<Words->Length;c++)
{
if(CheckNum[c]==RandNum)
{
RandNum = RandNumber->Next(0,number);
c=0;
}
}
int CheckInt = CheckNum->Length;
CheckNum[CheckInt] = RandNum;
I get the error: Object reference not set to an instance of an object. I'm not sure what I'm doing wrong. Any ideas? And I should probably define variables up top I know but I just add them when I need them when I'm troubleshooting, I can clean it up later. Oh and CheckNum is defined higher up in the code as: array<int^>^CheckNum;
Thanks for the help