Develop a function which can make the following operations: *Function should produce six completely different random numbers between 1 and 49
What did you do so far? Where did you have trouble?
What language?
There tend to be two types of random number generators that I have come across. The first is a random integer from 1 to the largest integer available. The second is a random float or double from 0 to less than 1. In both cases, if you want a random integer between `min` and `max`, you need to know the `range`. Suppose you have \(min\leq x \leq max\). We subtract \(min\) from both sides: \(0\leq x-min \leq max-min\). Then to change the \(\leq\) to a \(\lt\) we must add \(1\). \(0\leq x-min \lt max-min+1\) Ultimately \(0\leq x-min\lt range\) and so `range = max - min + 1`. For the 1 to max integer kind, we would use `(random % range) + min` For the 0 to 1 kind, we would use `floor(random * range) + min`
Join our real-time social learning platform and learn together with your friends!