I have two functions: The first one generates random numbers and the second one make a simulation to approximate the value of pi.
Public Function GetRandom(ByVal Min As Integer, ByVal Max As Integer) As Double
Static Generator As System.Random = New System.Random()
Return Generator.Next(Min, Max) / (Max - Min)
End Function
Then, the first function is inside the second function to generate the random values. What I want is sampling without repetition:
Public Function aproxpi(n As Integer) As Double
Dim contador As Integer = 0
Dim vector(n, 2) As Double
For i = 0 To n
' (0, 700) is a tuning parameter, I've seen that if I choose ( 0,10000) there's a less precise approximation due to repatead values
vector(i, 1) = GetRandom(0, 700)
vector(i, 2) = GetRandom(0, 700)
If (vector(i, 1) ^ 2 + vector(i, 2) ^ 2) < 1 Then
contador = contador + 1
End If
Next
aproxpi = 4 * (contador / n)
End Function
vector(i,1)
and vector(i,2)
are an (x,y)
pair. So I don't want (x,y)
pairs repeated.
So, how can I Avod repeated values in my code?