Hi Mike,
this is very dumb version, not very optimized ... but works
Petr
[code=thinbasic]
dim Numbers(1) as long
if Generate( Numbers, 10, 1, 10 ) = %TRUE then
msgbox 0, "Generated:"+$CRLF+join$(Numbers, ",")
else
msgbox 0, "Error ocurred"
endif
function Generate( byref arr() as long, xNumbers as long, nFrom as long, nTo as long )
local i as long
local f as long
' -- Make sure the array is properly dimensioned
if ubound(arr) <> xNumbers then
redim arr(xNumbers)
endIf
' -- Check if it is possible to generate such a series
if xNumbers > nTo-nFrom+1 then
msgbox 0, "Nice try, but impossible "
Return %FALSE
endIf
' -- Fill array with the numbers
for i = 1 to xNumbers
arr(i) = rnd(nFrom, nTo)
if i > 1 then ' -- Check if value was already used
f = 1
do
f = array scan arr(1) for i-1, =arr(i)
if f = 0 then exit do
arr(i) = rnd(nFrom, nTo)
loop
endIf
next
Return %True
end function
[/code]
Bookmarks