AI-powered learning
Save this course
Fixing Random: Techniques in C#
Gain insights into tackling uncertainty in C# programming. Delve into improving System.Random class with powerful techniques for efficient problem-solving and fewer bugs. Discover new language uses.
44 Lessons
20h
Updated this week
Join 2.9 million developers at
Join 2.9 million developers at
LEARNING OBJECTIVES
- Identify key flaws in System.Random (seeding, thread safety, exclusive ranges) that cause buggy outcomes
- Implement thread-safe and cryptographically secure random integers and doubles in C#
- Design continuous distributions using an IDistribution interface and visualize samples with histograms
- Build discrete distributions (uniform, weighted, Bernoulli, singleton) over values and C# objects
- Implement efficient weighted sampling via CDF+binary search, rejection sampling, and the alias method
- Apply Bayesian inference with priors and likelihoods to compute marginal and posterior probabilities in C#
- Estimate expected values using importance sampling and helper distributions for continuous weighted functions
Learning Roadmap
1.
Introduction to System.Random in C#
Introduction to System.Random in C#
Get familiar with System.Random's limitations and its impact on C# programming.
2.
Introduction to Fixing Random
Introduction to Fixing Random
Look at improvements to C#’s randomness, probability distributions, and sampling techniques.
3.
Fixing Random - Discrete Distribution
Fixing Random - Discrete Distribution
22 Lessons
22 Lessons
Master the steps to implement and optimize discrete distributions in C#, including Bernoulli and alias methods.
4.
Fixing Random - Continuous Distribution
Fixing Random - Continuous Distribution
13 Lessons
13 Lessons
Apply your skills to sampling and estimating expected values in continuous distributions.
5.
Conclusion
Conclusion
2 Lessons
2 Lessons
Explore probabilistic programming, improved tools, and efficient techniques for estimating values.
6.
Appendix
Appendix
2 Lessons
2 Lessons
See how it works to define and generate non-uniform random data in C#.
Certificate of Completion
Showcase your accomplishment by sharing your certificate of completion.
Complete more lessons to unlock your certificate
Developed by MAANG Engineers
ABOUT THIS COURSE
There are a lot of problems we face in programming that deal with uncertainty, statistics, and probabilities. Unfortunately, the majority of the general-purpose languages that we use on a daily basis don’t provide a great approach to solving them.
This is particularly the case in C# with the System.Random class. The implementations of this class have been pretty poor for some time. System.Random in C# regularly leads to unexpected, buggy outcomes.
If you’re a C# fan who’s looking for new ways to use the language, then this course is for you. It proposes different approaches to improving the System.Random class, providing a number of powerful techniques that solve problems more efficiently and with fewer lines of code.
ABOUT THE AUTHOR
Eric Lippert
Eric Lippert is a programming language designer, blogger, author and editor of programming books. See his fabulous adventures at ericlippert.com
Trusted by 2.9 million developers working at companies
A
Anthony Walker
@_webarchitect_
E
Evan Dunbar
ML Engineer
S
Software Developer
Carlos Matias La Borde
S
Souvik Kundu
Front-end Developer
V
Vinay Krishnaiah
Software Developer
Built for 10x Developers
No Passive Learning
Learn by building with project-based lessons and in-browser code editor


Personalized Roadmaps
The platform adapts to your strengths & skills gaps as you go


Future-proof Your Career
Get hands-on with in-demand skills


AI Code Mentor
Write better code with AI feedback, smart debugging, and "Ask AI"




MAANG+ Interview Prep
AI Mock Interviews simulate every technical loop at top companies


Free Resources