Reputation: 419
Let's say you have a random algorithm which can choose between 2 elements however you want the 2nd element to have a chance of only 1% to be selected. What is the algorithmic logic behind it? Also any idea on how I could find more on this matter? I researched random algorithms with determined output but couldn't find answer to my question.
I looked into Cryptographically secure pseudorandom number generator however I think that for now, it is not necessary to overcomplicate things.
Upvotes: 0
Views: 59
Reputation: 3891
int arr[2] = {1, 2};
return arr[(Math.floor(Math.random() * 100) == 0)? 1 : 0];
Upvotes: 1