Asp.net (c #) two random number algorithms, available for question Extraction

Source: Internet
Author: User

The first algorithm has a big problem. Not found Copy codeThe Code is as follows: static void Main (string [] args)
{
//
// TODO: Add code here to start the application
Int singletitlemeasure = 5;
Int n = 1; // declare an int variable that represents the test Type
Random ran = new Random (unchecked (int) DateTime. Now. Ticks ));
Int Int1Random;
Switch (n)
{
Case 1: // indicates a single answer
{
Int I = 1, k = 1;
Int [] ** I = new int [singletitlemeasure + 1]; // declare an array used to save question numbers
Int temp; // declare an array that temporarily saves random values
Int1Random = ran. Next (1, singletitlemeasure );
** I = Int1Random;
Console. WriteLine ("** I [" + I + "] =" + ** I );
Do
{K = 1; Int1Random = ran. Next (1, singletitlemeasure); temp = Int1Random; Console. WriteLine ("temp:" + temp); do {if (temp! = ** I [k]) {
Console. WriteLine ("** I [" + k + "] =" + ** I [k]);
K ++;
Console. WriteLine ("looping" + (k-1) + "times ");
}
Else
{
I --;
Console. writeLine ("I =" + I) ;}} while (k <I); I ++; ** I = temp; Console. writeLine ("** I [" + I + "] =" + ** I);} while (I <= singletitlemeasure-1); for (I = 1; I <= 5; I ++)
{Console. Write ("Int1Random ="); Console. WriteLine (** I );
} Break;
}
Case 2: // indicates multiple choice questions {Console. WriteLine ("Int2Random ="); break;
}
Case 3: // indicates a question.
{
Console. WriteLine ("Int3Random = ");
Break;
}
Default:
{Console. WriteLine ("Invalid selection. Please select 1, 2, or 3 .");
}
Break;
}
Console. Read ();
}

Copy codeThe Code is as follows: using System;
Namespace Temp
{
/// <Summary>
/// Summary of Class1.
/// </Summary>
Class Class1
{
/// <Summary>
/// Main entry point of the application.
/// </Summary>
[STAThread]
Static void Main (string [] args)
{
//
// TODO: Add code here to start the application
Int singletitlemeasure = 20; // number in the question bank
Int Int1Random; // random number generated temporarily
Int [] ** I = new int [singletitlemeasure + 1]; // declare an array used to save question numbers
Bool bflag = true;
Bool bFlag = true;
Int n = 1; // declare an int variable that represents the test Type
Int I = 1; // number of declared Outer Loops
Switch (n)
{
Case 1: // indicates a single answer
{
Do
{
// Random ran = new Random (unchecked (int) DateTime. Now. Ticks); // this Random number is somewhat regular.
Random ran = new Random (unchecked (int) DateTime. now. millisecond); // this random number is more random than some Int1Random = ran. next (1, singletitlemeasure + 1 );
// ** I = Int1Random;
// Console. WriteLine ("** I [" + I + "] =" + ** I );
Console. WriteLine ("Int1Random =" + Int1Random );
Int temp = Int1Random;
If (bFlag = true)
{
** I = Int1Random;
Console. WriteLine ("** I [" + I + "] =" + ** I );
BFlag = false;
I ++;
}
Else
{
Bflag = true;
Int k = 1; // number of declared inner Loops
Do
{
If (temp = ** I [k])
{
// Console. WriteLine ("** I [" + k + "] =" + ** I [k]);
Bflag = false;
Break;
}
K ++;
} While (k <I );
If (bflag = true)
{
** I [k] = temp;
Console. WriteLine ("** I [" + I + "] =" + ** I );
I ++;
}
}
} While (I <= 5 );

For (I = 1; I <= 5; I ++)
{
Console. WriteLine ("** I [" + I + "] =" + ** I );
}
Break;
}
Case 2: // multiple answer questions
{
Console. WriteLine ("Int2Random = ");
Break;
}
Case 3: // indicates a question.
{
Console. WriteLine ("Int3Random = ");
Break;
}
Default:
{
Console. WriteLine ("Invalid selection. Please select 1, 2, or 3 .");
}
Break;
}
Console. Read ();
//
}
}
}

Related Article

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.