import random
import math


def roulette_index(n, random=random):
    """Randomly choose an index from 0...n-1.  Choice has a weight of (index+1)."""
    rouletteValue = random.randint(0, n * (n-1) // 2)
    return math.ceil(-0.5 + math.sqrt(0.25 + 2 * rouletteValue))