Skip to content

What actually happens when we use a Random instance from multiple threads? Can we do something to make it thread-safe?

Notifications You must be signed in to change notification settings

CSharp-Pills-15mg/Random-Problems

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Random Problems

Description

There are rare occasions when we need to generate random numbers. C# offers a class for generating pseudo-random numbers. I will not explain in this pill what pseudo-random numbers are and how are they generated by C#. Instead, I want to highlight a problem that we may encounter when using the Random class: this class is not thread-safe.

This aspect will raise a couple of questions:

Questions

  • What actually happens when we use a Random instance from multiple threads?
  • Can we do something to make it thread-safe?

About

What actually happens when we use a Random instance from multiple threads? Can we do something to make it thread-safe?

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

Languages