2,722
社区成员
发帖
与我相关
我的任务
分享
*!* 4 + 1 的排列 (SQL-Select 算法) :
Clear
Close Databases
*!* 前 4 位的全排列
Create Cursor P1 (Num C(1), Digit I)
Insert Into P1 Values ('1', 1)
Insert Into P1 Values ('2', 2)
Insert Into P1 Values ('3', 4)
Insert Into P1 Values ('4', 8)
*!* 后 1 位的 4 选 1 组合
Create Cursor PP2 (Num C(1))
Insert Into PP2 Values ('1')
Insert Into PP2 Values ('2')
Insert Into PP2 Values ('3')
Insert Into PP2 Values ('4')
*!* P(4) x C(4, 4) = 96
Select P1.Num + P2.Num + P3.Num + P4.Num + P5.Num As 排列数 ;
From P1 P1, P1 P2, P1 P3, P1 P4, PP2 P5 ;
Where P1.Digit + P2.Digit + P3.Digit + P4.Digit = 15 ;
Order By 排列数
? Reccount()
*!* 5 个数的全排列 (SQL-Select 算法):
Clear
Close Databases
Create Cursor Permutations (排列数 C(5))
For I = 1 To 4
=视力表(I)
=Permutations()
Endfor
*!* 从查询结果中排除所有的重复行
Select Distinct * From Query
? Reccount()
Function 视力表(lnNun As Integer)
*!* 5 个数的全排列 : P(5) = 240
Create Cursor P1 (Num C(1), Digit I)
Insert Into P1 Values ('1', 1)
Insert Into P1 Values ('2', 2)
Insert Into P1 Values ('3', 4)
Insert Into P1 Values ('4', 8)
Insert Into P1 Values (Transform(lnNun), 16)
Endfunc
Function Permutations
*!* 5 的全排P : 120 种排P
Select Distinct P1.Num + P2.Num + P3.Num + P4.Num + P5.Num As 排列数 From ;
P1 P1, P1 P2, P1 P3, P1 P4 , P1 P5 ;
Where P1.Digit + P2.Digit + P3.Digit + P4.Digit + P5.Digit = 31 ;
Order By 1 Into Cursor Query
Select Permutations
Append From Dbf("Query")
Endfunc
然后可以随机取出该 60 个记录的任意一个#define K_最大行数 50
Create Cursor ttt (f1 I, f2 C(5))
Index on f2 tag f2
Rand(-1)
Do while Reccount() < K_最大行数
c1 = '1234'
c2 = ''
For ii = Len(c1) to 2 step -1
c0 = Substr(c1, getrandom(1, ii), 1)
c1 = Chrtran(c1, c0, '')
c2 = c2 + c0
EndFor
c3 = c2 + c1 + Transform(getrandom(1, 4))
If !Seek(c3)
Insert into ttt (f1, f2) values (1+Reccount(), c3)
EndIf
EndDo
Delete Tag all
Locate
Browse
Function getrandom(n1, n2)
Return n1 + Int(100*Rand()) % (1 + n2 - n1)
EndFunc
Clear
Rand(-1)
lnNum=5 &&生成随机数个数
Dimension nStr[lnNum]
N=0
Do While n<lnNum
nItem = Ceiling(lnNum*Rand())
If Ascan(nStr,nItem)=0
nStr[N+1]=nItem
N=N+1
EndIf
EndDo
Local a[5]
a[1]=1
a[2]=2
a[3]=3
a[4]=4
a[5]=4
For i=1 to 5
?a[nstr(i)] && 显示数组a中的元素值
EndFor
DIMENSION a[5]
FOR i=1 TO 4
a[i] = i
NEXT
a[i] = CEILING(RAND() * 4)
shuffle(@a)
shuffle(@a)
shuffle(@a)
shuffle(@a)
shuffle(@a)
FUNCTION shuffle(a)
LOCAL n, m, i, c
m = ALEN(a)
FOR i = 1 TO m
n = CEILING(RAND() * m)
c = a[i]
a[i] = a[n]
a[n] = c
NEXT
* 以下只是用于检查
?
FOR i=1 TO m
?? a[i]
NEXT