I got some help here the other day, randomizing an array. It worked great. But after re-thinking the situation, I saw it wouldn't do exactly what I needed it to do. So I augmented the code by adding a vector and changing some of the other code. It works...but it doesn't. When it randomizes now, I can't ever get 1. It's always a 0. Everything else is right. And no matter what I do, the number 1 always shows up as a 0.
var
setb: set of Byte = [];
idx: Byte;
a, i, j : Integer;
v : iVector;
arr : array[1..20] of Integer;
begin
{------------------------------------------------------------------------------
LET'S STORE THE IDs IN A VECTOR AND GET A RECORD COUNT
-------------------------------------------------------------------------------}
v := iVector.Create;
a := 0;
Memo1.Clear;
Memo2.Clear;
ZQ1.Close;
ZQ1.SQL.Text := 'SELECT amc_id FROM adultMultipleChoice';
ZQ1.Open;
ZQ1.First;
while not ZQ1.EOF do
begin
i := ZQ1.Fields[0].AsInteger;
v.PushBack(i);
Inc(a);
Memo1.Lines.Add(IntToStr(i));
ZQ1.Next;
end;
{-------------------------------------------------------------------------------
NOW WE'LL RANDOMIZE THE NUMBERS AND STORE THEM IN AN ARRAY
-------------------------------------------------------------------------------}
Randomize;
j := 0;
repeat
idx := Succ(Random(a));
case (idx in setb) of
True: ;
False: begin
Include(setb, idx);
Inc(j);
arr[j] := v[idx];
Memo2.Lines.Add(IntToStr(arr[j]));
end;
end;
until j = 20;
Like I said, most of this was a freebie from a Forum regular. And I don't understand all of it. I'll get there. But can someone tell me why I get a 0 in place of the 1? Thank you.
I attached the database. To do so I had to change the extension from .db to .txt