Random distributions in Go with inheritance
Style comments


Don't panic. Return the incorrect value of n in your error using fmt.Errorf.
Use gofmt on your code. (Have your favorite editor call it on-save.)
There is no better way to convert a bool to an int than what you have.
Replace var u = … by u := ….
No need to use named returned parameters in Rn.


On your main question

What you have works, but consider if one caller of your library does:

cont := Continuous{}
cont.Rn(42)


If you can't guess, try it; it's a good way to learn =) Anyway, you don't want that to happen. So you can do this several ways. Before I'm going into two idiomatic options, let's talk about your interface definitions:


Rn only needs something that implements R, so you could probably have an interface only for this. Let's call this interface Law.
Your Continuouser should simply be called Continuous or ContinuousLaw (because it describes what a continuous law does). In its definition, replace the R() float64 by Law.
Your Continuous should be called MultiDrawer or something. The only reason you're defining it is because you want to draw multiple values; so name it accordingly.


Option 1:

func Rn(law Law, n int) []float64


It's very simple; what you're saying here is "give me a Law, I can give you n random values from it".

Option 2:

interface MultiDrawer {
    Rn(n int) []float64
}

struct multiDrawer { // unexported: you don't want callers to touch this directly
    Law
}

func NewMultiDrawer(law Law) MultiDrawer {
    return &amp;multiDrawer(law)
}

func (md *multiDrawer) Rn(n int) []float64 {
    // your code using md.R()
}


You're saying something similar here: "give me a Law and I give you a MultiDrawer". It's better if you want to have a concept of a MultiDrawer variable that you'll later pass around or reuse.