Random Number Generator "Randomness" Check?
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- javascript
- Domain
- testing
Research direction
Start by locating the get_random_int function in the repository and run the JavaScript loop shown in the issue with the stated range and test count. The issue does not identify a file, test location, or requested repository change; clarify whether the distribution check should be added or documented before defining what done means.
Written by the indexing model from the issue text.
Description
Given the following "Random Integer between range X and Y" function:
/**
* Returns a random integer between min (inclusive) and max (inclusive)
* Using Math.round() will give you a non-uniform distribution!
* from: http://stackoverflow.com/a/1527820/1148249
*/
function get_random_int(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
We can run the following test to confirm the randomness:
var i = 0; // counter for looping.
var results = {}; // store the results of running get_random_int
var min = 0;
var max = 9;
for(i = min; i <= max; i++) {
results[i] = 0; // initialize results to zero;
}
i = 0; // reset/reuse i counter.
var test_count = 10000000;
while(i < test_count) {
var r = get_random_int(min, max);
results[r]++; // increment the count for a given random number
i++;
}
Object.keys(results).forEach(function(k) {
results[k] = results[k].toString() + ' > ' + (results[k] / test_count * 100).toFixed(3) + ' %';
});
console.log(JSON.stringify(results, null, 2));
Which outputs:
{
"0": "1000900 > 10.009 %",
"1": "999727 > 9.997 %",
"2": "999742 > 9.997 %",
"3": "999268 > 9.993 %",
"4": "1000650 > 10.007 %",
"5": "998621 > 9.986 %",
"6": "1000241 > 10.002 %",
"7": "1000716 > 10.007 %",
"8": "1000151 > 10.002 %",
"9": "999984 > 10.000 %"
}
Which is a pretty decent distribution...
- Dominant language
- HTML
- Stars
- 65
- Forks
- 15
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dwyl/learn-javascript
-
enhancement
dwyl/learn-javascript#39 · 1 assignee ·
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 20/100
dwyl/learn-javascript#38 · 3 reactions ·
-
JavaScript Grammar Open
Difficulty 5/5 Over a week Newbie friendliness 15/100
dwyl/learn-javascript#37 · 2 reactions ·
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 15/100
dwyl/learn-javascript#36 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 20/100
dwyl/learn-javascript#35 ·
All issues in dwyl/learn-javascript
Similar issues
-
fix(errors): EHOSTUNREACH from a happy-eyeballs connect is reported as a resolver error (STAMP-80) Open
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
snapshot-labs/stamp#666 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
GauravKarakoti/SecureFlow#1070 · 1 comment ·
-
agent/quality hive/hosted-available-lke648397-260827-5n31 quality testing
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100