//as we can return a function in go
//as we can pass function as a parameter in go
Here is what I mean by information of a function:
list of returned (data/function) types
list of its arguments (data/function) types with values
My general Goal is to get rid of very small ( super small near zero ) probabilities of some random values returned by function results.
The problem is that there ( super small near zero ) probability of duplicate results. it gets greater as the length of the result wanted gets smaller, and greater if generate more random values. ( are countless in my case )
here is an example :
func RandomPassword(min, max int) string {
...
return password
}
func RandomEmail() string {
return RandomStr(6) + "@" + RandomStr(6) + ".com"
// 6 is length of the returned string
}
func RandomName() string {
return RandomStr(12)
}
so I implemented a function to check whether two results are equal or not. he is my approach, but I don't know how to get information of a method using the reflect package, (which is my question)
//r is my random value
//f is a function that returns a random value
func RandomMustDiff(r any, f func(...any)) {
// if return(data/function)types == reflect.TypeOf(r) {
panic("types aren't equal")
}
// get the function arguments
args := f.args()
// check-results code
if r != f(args) {
return RandomMustDiff(r, f(args))
}
}