In flash, 10 different numbers are randomly generated between 20-, and the 10 numbers cannot be randomly retrieved repeatedly.

Source: Internet
Author: User

In a traffic light test, when the green light passes the yellow light, a random time starts to appear. The car scores during the specified time. Once the time is exceeded, the red light appears, the previous points are all 0; otherwise, the points are accumulated to the total score. One person performs ten tests, and the distance used each time is one of the 10 numbers that appear just now (of course this distance is invisible), winning the highest score.

AlgorithmThe key is to generate ten different random numbers and randomly retrieve these 10 random numbers 10 times (after the 10 random numbers are fixed, each tester uses these 10 numbers, however, the order of the 10 numbers cannot be the same ).

 

It should be noted that it is very difficult to randomly generate 10 different numbers from 1 to 10, and it is often unable to get the result after a long time. Therefore, the random number range is required to subtract the integer part, it is faster to leave a single digit.

The As script that generates 10 different random numbers is as follows:

VaR inttemp = 0;

Int_array = new array (10 );
Int_array [1] = math. Round (math. Random () * 80 + 20 );
VaR COUNT = 1;
VaR flags = 0;
Do {
Inttemp = math. Round (math. Random () * 80 + 20 );
For (I = 1; I <= count; I ++)
{
If (int_array [I] = inttemp)
{
Flags = 1; // indicates whether repeated numbers are found.
Break;
}
}

If (flags = 0) // if no duplicate number is found, record it
{
Count = count + 1;
Int_array [count] = inttemp;
}
Flags = 0;

 
 
} While (count <= 10)

 

Random out of the ten random numbersCodeAs follows:

First, randomly obtain different small labels and use these subscripts to identify different numbers.

VaR K = 0;
VaR flag;
Data1 = new array (10); // records 10 different tables and outputs
Data1 [1] = math. Round (math. Random () * 9 + 1 );
TOT = 1; // records the total number of cycles
VaR flag = 0;
Do {
Gen_data = math. Round (math. Random () * 19 + 1); // It is mainly used to prevent the occurrence of a large probability time with the same number at random in a small range.
If (gen_data> 10)
Gen_data = gen_data-10; // you can obtain the remainder
For (TT = 1; TT <= tot; TT ++)
{
If (gen_data = data1 [TT])
{
Flag = 1;
Break;
}
}
If (flag = 0)
{
TOT = tot + 1;
Data1 [tot] = gen_data;
}
Flag = 0;

} While (TOT <10 );

out1_txt = int_array [data1 [1];
out2_txt = int_array [data1 [2];
out3_txt = int_array [data1 [3];
out4_txt = int_array [data1 [4];
out5_txt = int_array [data1 [5];
out6_txt = int_array [data1 [6];
out7_txt = int_array [data1 [7];
out8_txt = int_array [data1 [8];
out9_txt = int_array [data1 [9];
out10_txt = int_array [data1 [10];
stop ();

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.