Skip to main content
Notice removed Reward existing answer by emanresu A
Bounty Ended with 97.100.97.109's answer chosen by emanresu A
Notice added Reward existing answer by emanresu A
Bounty Started worth 100 reputation by emanresu A
Tweeted twitter.com/StackCodeGolf/status/1594027726947729411
Post Reopened by rydwolf, loopy walt, pxeger, Seggan, lyxal
Left closed in review as "Original close reason(s) were not resolved" by caird coinheringaahin g, Wheat Wizard
elaborate and add test case
Added to review
Source Link
user1502040
  • 3.9k
  • 14
  • 23

Given an integer n >= 1 as input, output a sample from the discrete triangular distribution over the integers k, for 1 <= k <= n (1 <= k < n is also acceptable), defined defined by p(k) ∝ k.

E.g. if n = 3, then p(1) = 1/6, p(2) = 2/6, and p(3) = 3/6.

Your code should take constant expected time, but you are allowed to ignore overflow, to treat floating point operations as exact, and to use a PRNG (pseudorandom number generator).

You can treat your random number generator and all standard operations as constant time.

This is code golf, so the shortest answer wins.

Given an integer n >= 1 as input, output a sample from the discrete triangular distribution over the integers k, for 1 <= k <= n (1 <= k < n is also acceptable), defined by p(k) ∝ k. Your code should take constant expected time, but you are allowed to ignore overflow, to treat floating point operations as exact, and to use a PRNG.

This is code golf, so the shortest answer wins.

Given an integer n >= 1 as input, output a sample from the discrete triangular distribution over the integers k, for 1 <= k <= n (1 <= k < n is also acceptable), defined by p(k) ∝ k.

E.g. if n = 3, then p(1) = 1/6, p(2) = 2/6, and p(3) = 3/6.

Your code should take constant expected time, but you are allowed to ignore overflow, to treat floating point operations as exact, and to use a PRNG (pseudorandom number generator).

You can treat your random number generator and all standard operations as constant time.

This is code golf, so the shortest answer wins.

Post Closed as "Needs details or clarity" by Giuseppe, Ginger, Shaggy, caird coinheringaahin g, lyxal
deleted 20 characters in body
Source Link
user1502040
  • 3.9k
  • 14
  • 23

Given an integer n >= 1 as input, output a sample from the discrete triangular distribution over the integers k, for 1 <= k <= n (1 <= k < n is also acceptable), defined by p(k) ∝ k. Your code should take constant expected time, but you are allowed to ignore overflow, to treat floating point operations as exact, and to use a (reasonable quality) PRNG PRNG.

This is code golf, so the shortest answer wins.

Given an integer n >= 1 as input, output a sample from the discrete triangular distribution over the integers k, for 1 <= k <= n (1 <= k < n is also acceptable), defined by p(k) ∝ k. Your code should take constant expected time, but you are allowed to ignore overflow, to treat floating point operations as exact, and to use a (reasonable quality) PRNG.

This is code golf, so the shortest answer wins.

Given an integer n >= 1 as input, output a sample from the discrete triangular distribution over the integers k, for 1 <= k <= n (1 <= k < n is also acceptable), defined by p(k) ∝ k. Your code should take constant expected time, but you are allowed to ignore overflow, to treat floating point operations as exact, and to use a PRNG.

This is code golf, so the shortest answer wins.

Source Link
user1502040
  • 3.9k
  • 14
  • 23

Sample from the discrete triangular distribution

Given an integer n >= 1 as input, output a sample from the discrete triangular distribution over the integers k, for 1 <= k <= n (1 <= k < n is also acceptable), defined by p(k) ∝ k. Your code should take constant expected time, but you are allowed to ignore overflow, to treat floating point operations as exact, and to use a (reasonable quality) PRNG.

This is code golf, so the shortest answer wins.