注意:是整数数组啊
请各位帮忙!!!
请各位帮忙!!!
解决方案 »
- delphi中如何创建Excel对象
- delphi 如何让function返回array of 类型的结构
- 仅仅是打印一些单据,如送货单、生产单、领料单等,用Rave是否够用?
- 如何蜕变成DELPHI的开发高手?
- 是中国人的看看。
- Delphi中如何取出数据库的当前记录?
- 怎样取得主板的序列号?
- 请教:如何通过编程,在程序中获知机器的CPU类型、主频和CPU占用是多少?
- sos!!!!!
- 初学者: 如果我将一个主表,两个从表分别用三个datasource连接并放在dataMod中,我怎样在form调用中实现这三个结果集的主从连接关系
- 三个表都有同用一个键 ,要用数据构形把它们联系起来,语法该如何写?
- 我通过StoredProc返回了一个结果集,但不想全部显示在dbgrid里,应该怎样删除不想要的记录呢?
^_^
type
n=array of integer;
//Max-2>=Number
function G(Max:integer;Const Number:integer):n;
var i,j:integer;
Num:n;
Curr:integer;
Mark:boolean;
begin
Memo1.clear;
//取13个随机数
for i:=0 to Number do
begin
while true do
begin
Mark:=False;
//取1-14之间的随机数
Curr:=random(Max);
//0不取
while curr=0 do
Curr:=Random(Max);
//查找是否有相等的
for j:=0 to High(Num) do
if Curr=Num[j] then
begin
Mark:=true;
break;
end;
if not Mark then break;
end;
SetLength(Num,i+1);
Num[i]:=Curr;
end;
result:=Num;
end;
哥们儿,要是产生一百个,很慢的,不知道楼主要要多少到多少之间的随机数啊?
array1 : array[1..100] of integer;
i, j, temp : integer;
lg : boolean;
begin
i := 1;
lg := true;
Randomize;
while i <= 100 do
begin
//产生1到10000之间的随机数,想产生1到100的,把10000改成100就行了
temp := round(random(10000))+1;
for j := 1 to i do
begin
if array1[j] = temp then
begin
lg := false;
break;
end;
end;
if lg then
begin
array1[i] := temp;
i := i + 1;
end; end;
end;
不过这样非常慢,,不可能用到程序里
var Arr:array[ARR_LOW..ARR_HIGH] of integer;
pos1,pos2:integer;i:integer;
begin
//初始化随机数序列
Randomize;
//用有序的数字初始化数组,以保证绝对没有重复
for i:=ARR_LOW to ARR_HIGH do
Arr[i]:=i;
//打乱数组里面的顺序(也就是随即交换)
for i:=ARR_LOW to ARR_HIGH do//也可以把这里的ARR_HIGH改为其他数字,但是推荐大于等于ARR_HIGH的数字,太大了浪费时间,太小了生成的数列不太"随机" :P
begin
//随机交换两个元素
pos1:=Round(Random(ARR_HIGH))+ARR_LOW;
pos2:=Round(Random(ARR_HIGH))+ARR_LOW;
Arr[pos1]:=Arr[pos1] xor Arr[pos2];
Arr[pos2]:=Arr[pos1] xor Arr[pos2];
Arr[pos1]:=Arr[pos1] xor Arr[pos2];
end;
......................................
//ok,这个代码生成的随机数列绝对是没有重复的啦
end;
你你这样的算法可以限制最大的随机数吗??
你能帮我解释一下你的这个算法吗?
numset:set of 1..81;
n,m:integer;
begin
randomize;
n:=1;
numset:=[];
while n<=80 do
begin
m:=random(80);
if not(m in numset) then
begin
randomnum[n]:=m;
n:=n+1;
numset:=numset+[m];
end;
end;
end;
randomnum就是随机整数集合,绝对无重复
The range of a set type is the power set of a specific ordinal type, called the base type; that is, the possible values of the set type are all the subsets of the base type, including the empty set. The base type can have no more than 256 possible values, and their ordinalities must fall between 0 and 255. Any construction of the form
假如我要从0-400中间产生80个随机数呢?
你的还行不?
The base type can have no more than 256 possible values意思是不能超过256个值而不是指不能超过256。
你只用把m:=random(80);改成m:=random(400);就可以从0-400中间产生80个随机数。
不信你试一试。