以特定顺序生成随机数(符合方程式)以产生一系列特定结果

我想生成一个matrix(2×2)的随机数,以产生一个特定范围的结果。 特别是结果“决定因素”必须是下列之一:

(1或3或5或7或9或11或13或15或17或19或21或23或25)

并服从这个等式:

(RandomA x RandomY)-(RandomB x RandomZ)=one of the aforementioned Range of the "Determinant" 

(从左到右):

A是matrix第一行中的第一个单元格。
B是matrix第一行中的第二个单元格。
Z是matrix第二行中的第一个单元格。
Y是matrix第二行中的第二个单元格。

换句话说:我希望当我点击“现在计算”给四个随机数 – 在matrix中 – 随机产生上述结果之一。

适应类似于:

 Sub Yahya() Dim wf As WorksheetFunction Set wf = Application.WorksheetFunction Dim detDesired As Long result = Array(1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25) Dim A1 As Range, A2 As Range, B1 As Range, B2 As Range, C3 As Range Set A1 = Range("A1") Set A2 = Range("A2") Set B1 = Range("B1") Set B2 = Range("B2") Set C3 = Range("C3") detDesired = result(wf.RandBetween(0, 12)) C3 = detDesired A1 = wf.RandBetween(1, 20) B1 = wf.RandBetween(-10, 10) A2 = wf.RandBetween(-10, 10) B2 = (C3 + A2 * B1) / A1 End Sub 

我们在C3中存储行列式。 调整随机select的领域,以满足您的需求:

在这里输入图像说明

方法是随机select行列式和四个matrix元素中的三个; 然后计算第四个元素(因为问题受到限制)