Home > Back-end >  The couple asked, questions about randomly
The couple asked, questions about randomly

Time:09-28

Questions about randomly, I want to do as a result of such as the extraction of the records, pulled out not draw on to the next time, such as 10 records collected 7, next time extraction of article 7, article 3 to the results have not been extracted, the other four cycle extraction, the reciprocating, I'm new everybody don't laugh at my question, thank you, prawns help, don't know how to write,,, the procedure is as follows,

Implementation

USES the Main, Extract1Rep ExtractResult;

{$R *. DFM}

//take a function and returns an array containing extraction results
The function ExtractFunc (const m_count e_count: integer; Var TArray: an array of integer) : string;
Var
X, I: integer;
St: string;
The begin
If e_count & lt;=0 then the exit;
//if e_count & gt; M_count will appear dead cycle, so judgment and jump out of the loop
If e_count & gt; M_count then
The begin
Application. MessageBox (' extraction number cannot be greater than the total extract. ', 'prompt', MB_OK);
exit;
end;
I:=1;
St:=';
While i<=e_count do
The begin
Randomize.
X:=the Random (m_count) + 1;//produce 1 ~ m_count random number
//if the extraction to the random number x is not extract before, it is saved to the st, the comma separated
If ansipos (Quotedstr (inttostr (x)) + ', ', st) & lt;=0 then
The begin
St:=st + Quotedstr (inttostr (x)) + ', ';
TArray: [I - 1]=x;
I:=I + 1;
end;
end;
Result:=st;

end;

CodePudding user response:

Article 10 records collected 7, next time extraction of article 7, article 3 to the results have not been extracted, the other four cycle extraction of

Feel a little dizzy, such randomness can good?
Idea: each record to increase the number one is extracted information
Every time extraction, according to the number (trans) + random sort, extract to record, number plus one

CodePudding user response:

reference 1st floor sz_haitao response:
10 records collected 7, next time extraction of article 7, article 3 to the results have not been extracted, the other four cycle extraction of

Feel a little dizzy, such randomness can good?
Idea: each record to increase the number one is extracted information
Every time extraction, according to the number (trans) + random sort, extract to record, number plus one

I can express a bit is not clear, is the cycle is not repeated, this how to write, how to change on the basis of the existing code under? Thank you very much!

CodePudding user response:

Randomize.
X:=the Random (m_count) + 1;//produce 1 ~ m_count random number
Such a random number, extraction, the more the number of each is extracted, incline to average,

However, for your problem, the number of extraction will not too much, so, need by means of the data is divided into several levels:
Level 1: extracting=0
Level 2:3 & gt; Extracting times & gt;=1
Level 3: extracting times & gt; 2
Partial extraction:
(1) the first inside out at level 1
(2) if the data is not reached, then drew within 2
(3) if the data is not reached, then drew within 3
,,,,,,,,,


  • Related