Skip to main content
added 58 characters in body
Source Link
tsh
  • 35.6k
  • 2
  • 34
  • 129

JavaScript (Node.js), 72 bytes

s=>Buffer(s).map(c=>Math.random()<n/l--/2?(n-=2,c-32):c,n=l=s.length)+''

Try it online!Try it online!

Basic idea: To Choose \$n\$ items from \$l\$ candidates, each item have \$\frac{n}{l}\$ probability to be chosen. And once the first item is chosen, we need to choose \$n-1\$ items from remaining \$l-1\$ candidates. If the first item is not chosen, we need to choose \$n\$ items from remaining \$l-1\$ candidates.

JavaScript (Node.js), 72 bytes

s=>Buffer(s).map(c=>Math.random()<n/l--/2?(n-=2,c-32):c,n=l=s.length)+''

Try it online!

Basic idea: To Choose \$n\$ items from \$l\$ candidates, each item have \$\frac{n}{l}\$ probability to be chosen. And once the first item is chosen, we need to choose \$n-1\$ items from remaining \$l-1\$ candidates. If the first item is not chosen, we need to choose \$n\$ items from remaining \$l-1\$ candidates.

JavaScript (Node.js), 72 bytes

s=>Buffer(s).map(c=>Math.random()<n/l--/2?(n-=2,c-32):c,n=l=s.length)+''

Try it online!

Basic idea: To Choose \$n\$ items from \$l\$ candidates, each item have \$\frac{n}{l}\$ probability to be chosen. And once the first item is chosen, we need to choose \$n-1\$ items from remaining \$l-1\$ candidates. If the first item is not chosen, we need to choose \$n\$ items from remaining \$l-1\$ candidates.

added 317 characters in body
Source Link
tsh
  • 35.6k
  • 2
  • 34
  • 129

JavaScript (Node.js), 72 bytes

s=>Buffer(s).map(c=>Math.random()<n/l--/2?(n-=2,c-32):c,n=l=s.length)+''

Try it online!Try it online!

Basic idea: To Choose \$n\$ items from \$l\$ candidates, each item have \$\frac{n}{l}\$ probability to be chosen. And once the first item is chosen, we need to choose \$n-1\$ items from remaining \$l-1\$ candidates. If the first item is not chosen, we need to choose \$n\$ items from remaining \$l-1\$ candidates.

JavaScript (Node.js), 72 bytes

s=>Buffer(s).map(c=>Math.random()<n/l--/2?(n-=2,c-32):c,n=l=s.length)+''

Try it online!

JavaScript (Node.js), 72 bytes

s=>Buffer(s).map(c=>Math.random()<n/l--/2?(n-=2,c-32):c,n=l=s.length)+''

Try it online!

Basic idea: To Choose \$n\$ items from \$l\$ candidates, each item have \$\frac{n}{l}\$ probability to be chosen. And once the first item is chosen, we need to choose \$n-1\$ items from remaining \$l-1\$ candidates. If the first item is not chosen, we need to choose \$n\$ items from remaining \$l-1\$ candidates.

Source Link
tsh
  • 35.6k
  • 2
  • 34
  • 129

JavaScript (Node.js), 72 bytes

s=>Buffer(s).map(c=>Math.random()<n/l--/2?(n-=2,c-32):c,n=l=s.length)+''

Try it online!