15,667,738 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View Javascript questions
View Python questions
View C++ questions
View Java questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by myker (Top 5 by date)
myker
9-Sep-11 18:25pm
View
Deleted
After running tests, I have to conclude that Richard is correct... The AsParallel() apples to the OrderBy clause, thereby invoking the Random class in a non-threadsafe way. This doesn't noticably affect the outcome, as the orderby clause shuffles position and the results are random enough. That said, it's still bad practice, and a good parallelization solution for using Random can be found here:
http://www.albahari.com/threading/part5.aspx
under the section entitled "Using ThreadLocal<T>"
myker
9-Sep-11 17:51pm
View
Deleted
Richard... after further investigation, the AsParallel() is applied to Range(), which generates a range of numbers and appears to be thread safe. The OrderBy, which is where the Random function is used, is resolved with each enumeration, and not in parallel. Though, this is still useful knowledge because the programmer should keep this in mind and not enumerate the result using the Parallel library.
As I understand it, OrderBy needs a fully enumerated result set in order to work, so it blocks until Range is completed, which is where the AsParallel is being applied.
Please, anyone out there, correct me if I am misunderstanding this.
myker
9-Sep-11 17:40pm
View
Deleted
Good catch, Richard! That's really good to know. I'm removing the "AsParallel" from the alternative.
myker
2-Sep-11 11:12am
View
Deleted
I'm not sure I understand your comment. Can you explain further?
myker
1-Sep-11 23:30pm
View
Deleted
Thank you! Glad to be of some help.