确实不应有重复的随机数。
Set Talk Off
Clear
Input"请输入一个数:" To N
F=.T.
CREATE CURSOR t1 (n1 int)
Dimension a(10)
?"随机数为:"
For i=1 To 10
DO whil .t.
n2=Int(Rand()*10+1)
SELECT t1
LOCATE FOR n1=n2
IF NOT FOUND()
INSERT INTO t1 (n1) VALUES (n2)
a(i)=n2
EXIT
ENDIF
ENDDO
??a(i)
NEXT
USE IN t1
For i=1 To 10
If a(i)=N
F=.F.
?"位置是:",i
Exit
Endif
Next
If F=.T.
?"未出现"
Endif
Set Talk Off
Clear
Input"请输入一个数:" To N
F=.T.
CREATE CURSOR t1 (n1 int)
Dimension a(10)
?"随机数为:"
For i=1 To 10
DO whil .t.
n2=Int(Rand()*10+1)
SELECT t1
LOCATE FOR n1=n2
IF NOT FOUND()
INSERT INTO t1 (n1) VALUES (n2)
a(i)=n2
EXIT
ENDIF
ENDDO
??a(i)
NEXT
USE IN t1
For i=1 To 10
If a(i)=N
F=.F.
?"位置是:",i
Exit
Endif
Next
If F=.T.
?"未出现"
Endif