SoFunction
Updated on 2025-03-07

(c#) Two random numbers algorithms, random test questions can be used


using System; 
namespace Temp 

/// <summary> 
/// Class1  summary description.
/// </summary> 
class Class1 

/// <summary> 
/// The main entry point of the application.
/// </summary> 
[STAThread] 
static void Main(string[] args) 

// 
// TODO: Add code here to start the application
int singletitlemeasure=20;//The number in the question bank
int Int1Random;//Temporarily generated random number
int[] **i=new int[singletitlemeasure+1];//Declare an array to save the question number
bool bflag=true; 
bool bFlag=true; 
int n=1;//Declare an int variable representing the exam type
int i=1;//Declare the number of external loops
switch(n) 

case 1://expressed as a single choice question

do 

//Random ran=new Random(unchecked((int)));//The random numbers generated in this way are somewhat regular
Random ran=new Random(unchecked((int)));//The random numbers generated in this way are more random Int1Random=(1,singletitlemeasure+1);
//**i=Int1Random; 
//("**i["+i+"]="+**i); 
("Int1Random="+Int1Random); 
int temp=Int1Random; 
if( bFlag==true) 

**i=Int1Random; 
("**i["+i+"]="+**i); 
bFlag=false; 
i++; 

else 

bflag=true; 
int k=1;//Declare the number of internal loops
do 

if(temp==**i[k]) 

//("**i["+k+"]="+**i[k]); 
bflag=false; 
break; 

k++; 
}while(k<i); 
if( bflag==true) 

**i[k]=temp; 
("**i["+i+"]="+**i); 
i++; 


}while(i<=5); 

for(i=1;i<=5;i++) 

("**i["+i+"]="+**i); 

break; 

case 2://expressed as a multi-choice question

("Int2Random="); 
break; 

case 3://denoted as a judgment question

("Int3Random="); 
break; 

default: 

("Invalid selection. Please select 1, 2, or 3."); 

break; 

(); 
//