Code center > Suggestions
More realistic mutations
Botsareus:
Yes that the correct formula, notice how the uncertainty in the following example becomes less and less. Btw you have to wait a good minute to see good results every 10 seconds:
--- Quote ---Dim a As Long
Dim b As Long
Private Sub Form_Load()
On Error Resume Next
Randomize
Show
Do
If Int(Rnd * 2) = 0 Then a = a + 1 Else b = b + 1
If Int(Timer) / 10 = Int(Timer) \ 10 Then Caption = a / b ' should be one
DoEvents
Loop
End Sub
'Bling Bling Nothing wrong with this test , All GOOD
--- End quote ---
Botsareus:
If you still dont like it try
negativeorpositive = (Int(Rnd * 2) * 2) - 1
this does not solve your issue but at least it does not use iif
Numsgil:
The problem with inventing things yourself is that it may not be random. I'm not sure how to test if something is truly random, but the function must satisfy a stats test of some sort (chi-squared maybe?) and have a large period (how long it takes to repeat itself).
Botsareus:
whats wrong with the test I just posted?
Numsgil:
Here's how values are currently changed in the program. Notice that it uses a looping method of gaussian generation:
Public Function PiuMeno() As Integer
PiuMeno = Random(0, 1)
If PiuMeno = 0 Then PiuMeno = -1
End Function
Public Function Gauss(low, up) As Long
For t = 1 To 10
Gauss = Gauss + Random(low, up)
Next t
Gauss = Gauss / 10
End Function
k = DNA(t).value + PiuMeno * Gauss(1, DNA(t).value + PiuMeno * 10)
If k < -32000 Then k = 32000
If k > 32000 Then k = 32000
DNA(t).value = Int(k)
Bots, the problem I'm talking about needs a double or single to isolate. Try your test code with a and b as singles, and you'll see your caption probably isn't exactly 1.000000000000000000. Run it for ever, and it still won't be 1.00000000000000000000 even though it should be. No randomizer is perfect. That is what I'm talking about. Some randomizers are much better at eliminating bias than others are, though.
Finding good methods to generate random numbers with no bias is Computer Science doctoral dissertation stuff. It's big business. It takes alot of math (more math than I know and I'm a math major).
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version