-3
This challenge is to generate a random floating-point number between 2 limits. You may use any language so long as it can be called from the command line, and runs on linux. It must also be able to work with negative numbers.
Due to the comment below: You may use fixed point math to come up with a result in-fact fixed point math is preferable in this case.
Input Requirements
Accept a lower and upper limit, no verification required.
Output Requirements
- Must be between the 2 specified limits
- Print it out to the console
- or come up with a way to return it to the shell.
Example
$ prog -1 1
-.445
The program would not spit out a result that is not between those 2 limits. And it would be inclusive of the 2 limits
Win Condition
As with all of these challenges the smallest number of bytes wins.
Can the first input be greater than the second? – Zgarb – 2015-03-22T17:28:16.747
@Zgarb so long as the output remains between the 2 limits – HSchmale – 2015-03-22T17:29:57.767
5Does the random number have to be uniformly distributed between those limits, or will a non-uniform distribution do? And must every floating point number between those limits be a possible output? (If yes, that technically excludes most standard random number generator APIs, and will require considerable knowledge of the internals of the floating-point format to implement correctly. On the other hand, an unqualified "no" would seem to allow e.g. a solution that only ever returns one of the two limits, never anything in between.) – Ilmari Karonen – 2015-03-22T17:42:27.893
4In particular, notably, due to the fact that floating-point numbers themselves are not uniformly distributed on the real number line, an RNG cannot satisfy more than two of the following three properties: 1) The distribution of the generated numbers approximates a continuous uniform distribution on the target interval. 2) Every floating-point number within the target interval is generated with a non-zero probability. 3) Every floating-point number that can be generated is generated with the same probability. Thus, you really should specify which (if any) of those properties you require. – Ilmari Karonen – 2015-03-22T17:48:05.447