I'm also a bit surprised that there is .random fun...
# stdlib
z
I'm also a bit surprised that there is .random function, but there is no way to give optional distribution to the function to do some kind of softmax that is imho very useful (at least in ML).
i
This sounds rather like a domain-specific request. But anyway, in what form do you propose to pass that distribution to
random()
?
z
I agree that that may sound domain-specific. I think it can be something like Collection<T>.random(distribution: Collection<Double>) or not collection, but also an array or a double array. Also, it may be useful to let sum of the distribution elements be different postive number from 1. If so, we can also support integers for distribution. Example: listOf('a', 'b', 'c', 'd').random(distribution = listOf (1, 2, 2, 5)) p('a') = 1/sum = 0.1 p('b') = p('c') = 0.2 p('d') = 0.5
I meant not distribution but weights, of course. Sorry for the wrong word, please.
Such relative weights are in random.choice in python.