Skip to content

Instantly share code, notes, and snippets.

@dfkaye
Last active April 20, 2019 16:39
Show Gist options
  • Save dfkaye/ea45ec072269d23dec993f46b3ebccbe to your computer and use it in GitHub Desktop.
Save dfkaye/ea45ec072269d23dec993f46b3ebccbe to your computer and use it in GitHub Desktop.
random-hex-string - create a random hex value string
// Dec 27, 2018
// create a random hex value string
var hex = function() {
return Math.floor(Date.now() * Math.random()).toString(16);
}
// test it out
var values = Array(1000000).fill(0).map(function() {
return hex();
});
// track any duplicate values
var dupes = values.reduce(function(dupes, value) {
value in dupes.visited || (dupes.visited[value] = 0);
dupes.visited[value] += 1;
if (dupes.visited[value] > 1) {
dupes.values[value] = dupes.visited[value]
}
return dupes;
}, { values: {}, visited: {} });
console.log(Object.keys(dupes.values).length);
console.log(dupes.values);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment