Charcoal, 14 bytes
I⌊₂⁺¹·⁵‽X⁺·⁵N²I⌊⁺·⁵₂⊕‽X⁺·⁵N²
Try it online!Try it online! Link is to verbose version of code. Explanation:
N Input `n` as a number
⁺·⁵ Plus literal number `0.5`
X ² Squared
‽ Random element of implicit range
⁺¹·⁵ ⊕ Plus literal number `1.5`Incremented
₂ ₂ Square root
⁺·⁵ Plus literal number `0.5`
⌊ Floor
I Cast to string
Implicitly print
Example: For n=4
, the implicit range is [0..20)
, which the remaining code maps 0..1
to 1
, 2..5
to 2
, 6..11
to 3
and 12..19
to 4
, thus p(k)∝k
as desired.