random number generator, seed, solver

michaelsmith559

Well-known Member
Joined
Oct 6, 2013
Messages
881
Office Version
  1. 2013
  2. 2007
I want to know if it is possible to have excel input a list of random numbers (I will show macro I am currently using and results) based on a starting seed (I have read about using rnd -1 before randomize but am not sure how to make that work for repeating a sequence. If I can make excel repeat the sequence and change the sequence by changing rnd -1 to rnd -2, then I would like to use solver to find the best seed for a "predictable" spacing. Here is my sheet the first 20 rows:


Excel 2007
QRSTU
1ValueRandomTrialsDesired SpacingSeed
21162-1
333244
433266
544488
6556510
7117412
8117814
9448016
10338618
118810420
128810722
139912524
149913626
152215528
163315930
175515932
187718034
191121736
209923338
One


Here is the macro I used to generate the random values and to count the number of trials it took to reach the value in column Q.

Code:
Sub Macro1()

Dim LRandomNumber As Integer, icount As Long, i As Long, lr As Long
lr = Cells(Rows.Count, "Q").End(xlUp).Row
icount = 0

For i = 2 To lr
    LRandomNumber = Int((9 - 1 + 1) * Rnd + 1)
    Cells(i, "R").Value = LRandomNumber
    While Cells(i, "R").Value <> Cells(i, "Q").Value
    LRandomNumber = Int((9 - 1 + 1) * Rnd + 1)
    Cells(i, "R").Value = LRandomNumber
    icount = icount + 1
    Wend
    Cells(i, "S").Value = icount
Next i
End Sub

Column T has the desired spacing I would like to have between the trials in column S. Would it be possible to somehow use a random seed, and have solver change the seed so that the number of trials in column s has a more linear/predictable spacing (again I have read about using rnd -1 to repeat a pattern which could be useful if solver could change the seed and achieve what I want)?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,215,746
Messages
6,126,641
Members
449,325
Latest member
Hardey6ix

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top