5桁に関しては前のプログラムを少し変更するだけで大丈夫です。
10桁も変更だけで対応できますがさすがにメモリの無駄遣いなので方法を変えています。
(表示方法も変えました。10がありますから数字で表記は無理です。)
1.五桁 内容は以前と同じ
Sub test2()
Dim Numset(15119) As Long, ct As Long
Dim ct1 As Long, temp As Long, rndno As Long
Randomize
For ct = 12345 To 98765
If handan(ct) Then Numset(ct1) = ct: ct1 = ct1 + 1
Next
For ct = 0 To 15118
rndno = Int(Rnd() * (15120 - ct))
temp = Numset(rndno)
Cells(ct + 1, 1) = temp
Numset(rndno) = Numset(15119 - ct)
Numset(15119 - ct) = temp
Next
Cells(15120, 1) = Numset(0)
End Sub
Private Function handan(num As Long) As Boolean
Dim ct As Integer, data(4) As Integer, kake As Long
For ct = 0 To 4
data(ct) = Int((num Mod 10 ^ (5 - ct)) / 10 ^ (4 - ct))
Next
kake = (data(0) - data(1)) * (data(0) - data(2))
kake = kake * (data(0) - data(3)) * (data(1) - data(2))
kake = kake * (data(1) - data(3)) * (data(2) - data(3))
kake = kake * data(0) * data(1) * data(2) * data(3) * data(4)
kake = kake * (data(0) - data(4)) * (data(1) - data(4))
kake = kake * (data(2) - data(4)) * (data(3) - data(4))
If kake Then handan = True: Exit Function
handan = False
End Function
2.10桁 一応、ランダムになるはずです。300個表示します。
Sub test3()
Dim Numset(299, 9) As Integer
Dim kakuSuji(9) As Integer
Dim kakunin(299) As Double, sum As Double
Dim ct As Integer, ct1 As Integer, temp As Integer, rndno As Integer
Dim flg As Boolean
Randomize
For ct1 = 0 To 9
kakuSuji(ct1) = ct1
Next
Do While ct < 300
For ct1 = 0 To 8
rndno = Int(Rnd() * (10 - ct1))
temp = kakuSuji(rndno)
kakuSuji(rndno) = kakuSuji(9 - ct1)
kakuSuji(9 - ct1) = temp
Next
sum = 0#: flg = True
For ct1 = 0 To 9
sum = sum / 10 + kakuSuji(ct1)
Next
For ct1 = 0 To ct - 1
If kakunin(ct1) = sum Then flg = False
Next
If flg Then
kakunin(ct) = sum
For ct1 = 0 To 9
Numset(ct, ct1) = kakuSuji(ct1) + 1
Next
ct = ct + 1
End If
Loop
Range(Cells(1, 1), Cells(300, 10)) = Numset()
End Sub
お礼
うまくできました!!とても助かりました。 2度もご回答していただき、本当にありがとうございました!!