asp.net (C #) Two kinds of random number algorithm, can be used to extract the practical skills of the exam

Source: Internet
Author: User
Tags datetime
The first algorithm, save a little bigger problem. Didn't find out.
Copy Code code as follows:

static void Main (string[] args)
{
//
TODO: Add code here to start the application
int singletitlemeasure=5;
int n=1;//declares an int variable that represents the test type
Random ran=new Random (Unchecked ((int) DateTime.Now.Ticks));
int int1random;
Switch (n)
{
Case 1://as single selection
{
int i=1,k=1;
Int[] **i=new int[singletitlemeasure+1];//declares an array to hold the title number
int temp;//declares an array that temporarily holds random values
Int1random=ran. Next (1,singletitlemeasure);
**i=int1random;
Console.WriteLine ("**i[" +i+ "]=" +**i);
Todo
{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 ("Circular" + (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://expressed as multiple selection {Console.WriteLine ("int2random=");
}
Case 3://expressed as a judgment question
{
Console.WriteLine ("Int3random=");
Break
}
Default
{Console.WriteLine ("Invalid Selection"). Please select 1, 2, or 3. ");
}
Break
}
Console.read ();
}

Copy Code code as follows:

Using System;
Namespace Temp
{
<summary>
Summary description of the CLASS1.
</summary>
Class Class1
{
<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main (string[] args)
{
//
TODO: Add code here to start the application
int singletitlemeasure=20;//The number of questions in the item bank
Random number of an int int1random;//temporarily generated
Int[] **i=new int[singletitlemeasure+1];//declares an array to hold the title number
BOOL Bflag=true;
BOOL Bflag=true;
int n=1;//declares an int variable that represents the test type
int i=1;//declaration Outer Loop number
Switch (n)
{
Case 1://as single selection
{
Todo
{
Random ran=new Random (((int) DateTime.Now.Ticks)); The random number that's generated is a bit of a rule.
Random ran=new Random ((int) DateTime.Now.Millisecond);//This produces a random number more random 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;//Declaration Inner Loop number
Todo
{
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://expressed as multiple selection
{
Console.WriteLine ("Int2random=");
Break
}
Case 3://expressed as a judgment 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.