Di dalam loop Anda dapat menggambar angka acak dan hanya memasukkannya (dan mengurangi loopcounter) jika tidak ada. Kode Pseudo :
while (counter > 6)
loop:
this = 1+ random() *1000
insert into weighed_directed_edge (startpoint, endpoint, costs)
VALUES ( :frompoint, :this, xxx* random() )
WHERE NOT EXISTS (
SELECT(*) FROM weighed_directed_edge nx
WHERE nx.startpoint = :frompoint
AND nx.endpoint = :this
);
if (rowcount > 0) counter -= 1;
end loop;