Spooky Sale: 10% off Premium yearly · $118.80 for the first year · until Nov 6Get it

Deep-ML
Learn
Problems1,200+ hands-on ML problemsLearning PathA guided route through the fundamentalsLabsInteractive labs on real techniquesProjectsBuild a GPT, an RL agent, CUDA kernelsCollectionsCurated problem sets and videosMathPen-and-paper math for MLIntuitionInvent the idea behind the formula yourselfPlaylistsYour own problem lists, shareableStudy AssistantAn AI teacher that knows your progress
Interview Prep
Compete
ContestsFresh problem sets, ranked liveLeaderboardWhere you stand, globallyBuddiesSolve with a friend: streaks, a weekly board, chat
Discuss
Deep-Path
Premium
      Intuition
      31 of 88

      Roll a loaded die

      A loaded die doesn’t land on every outcome equally often: chances[i] is how often outcome i comes up, and the chances add up to 1. A computer can only roll fair: random.random() gives a roll, a number from 0 up to (not including) 1, every value equally likely. Write pick(chances, roll): the outcome (its index, from 0) that this roll gives, so that over many rolls each outcome comes up as often as its chance. The same roll always gives the same outcome.

      chances
      outcome 0outcome 1outcome 2
      0.50.30.2
      roll
      0.62
      solution.pyLoading Python
      ← Too big for the computerCut the long tail →