A normal distribution has no upper or lower bound, so NormFloat64
might not be what you want.
This expression will give you a random float bounded to [-0.001,0.001):
(rand.Float64() * 2 - 1) * 0.001
Andrew
If that's the case then
MyVal := rand.NormFloat64() * ( 0.001 / n )
You can clamp it afterwards with a switch
switch {
case MyVal > 0.001:
MyVal = 0.001
case MyVal < -0.001:
MyVal = -0.001
}
But again, this won't be a normal distribution anymore...
A normal distribution has no upper or lower bound, so NormFloat64
might not be what you want.This expression will give you a random float bounded to [-0.001,0.001):
(rand.Float64() * 2 - 1) * 0.001
Andrew
func random(min, max float64) float64 {
return rand.Float64() * (max - min) + min
}
On Tue, Mar 27, 2012 at 20:49, Guillermo Estrada <phro...@gmail.com> wrote:
> How can it be done to use any arbitrary max min values?
--
matt kane's brain
http://hydrogenproject.com
This should do it:func random(min, max float64) float64 {
return rand.Float64() * (max - min) + min
}
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/_M-8hRpQs84/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Regards,
Alok Kumar Singh
Platform Engineering
+ 91 9880121029
I have fixed it thanks
-j