<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.silverlight.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Silverlight Tip of the Day #77 - Creating an Efficient Random Generator</title><link>http://blogs.silverlight.net/blogs/msnow/archive/2008/12/01/silverlight-tip-of-the-day-77-creating-an-efficient-random-generator.aspx</link><description>In some of my older posts I was creating a separate random generator for each object. However, the documentation on Random states: &amp;quot;The default seed value is derived from the system clock and has finite resolution. As a result, different Random objects</description><dc:language>en</dc:language><generator>CommunityServer 2007 (Build: 20416.853)</generator><item><title>Silverlight Tips of the Day – Week 10</title><link>http://blogs.silverlight.net/blogs/msnow/archive/2008/12/01/silverlight-tip-of-the-day-77-creating-an-efficient-random-generator.aspx#158071</link><pubDate>Thu, 08 Jan 2009 23:36:59 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:158071</guid><dc:creator>Visual Web Developer Team Blog</dc:creator><description>&lt;p&gt;This link provides a complete Tips of the Day Summary Outline - &lt;a rel="nofollow" target="_new" href="http://silverlight.net/blogs/msnow/archive/2009/01/02/silverlight-tips-of-the-day-summary-outline.aspx"&gt;silverlight.net/.../silverlight-tips-of-the-day-summary-outline.aspx&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=158071" width="1" height="1"&gt;</description></item><item><title>presentão de Ano Novo: dúzias de dicas e tutoriais de Silverlight ;)</title><link>http://blogs.silverlight.net/blogs/msnow/archive/2008/12/01/silverlight-tip-of-the-day-77-creating-an-efficient-random-generator.aspx#155414</link><pubDate>Sat, 03 Jan 2009 11:26:06 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:155414</guid><dc:creator>o UAU nosso de cada dia</dc:creator><description>&lt;p&gt;essa lista eu copiei desse blog b&amp;#225;rbaro (acompanhe por RSS voc&amp;#234; tamb&amp;#233;m): uma lista de dicas super &amp;#250;teis&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=155414" width="1" height="1"&gt;</description></item><item><title>Silverlight Tips of the Day - Summary Outline</title><link>http://blogs.silverlight.net/blogs/msnow/archive/2008/12/01/silverlight-tip-of-the-day-77-creating-an-efficient-random-generator.aspx#155179</link><pubDate>Fri, 02 Jan 2009 22:57:21 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:155179</guid><dc:creator>Silverlight Tips of the Day - Blog by Mike Snow</dc:creator><description>&lt;p&gt;The purpose of this post is to create an outline summary all the blogs from my Silverlight tips of the&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=155179" width="1" height="1"&gt;</description></item><item><title>Silverlight Tips of the Day - Summary Outline</title><link>http://blogs.silverlight.net/blogs/msnow/archive/2008/12/01/silverlight-tip-of-the-day-77-creating-an-efficient-random-generator.aspx#155178</link><pubDate>Fri, 02 Jan 2009 22:57:21 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:155178</guid><dc:creator>Silverlight Tips of the Day - Blog by Mike Snow</dc:creator><description>&lt;p&gt;The purpose of this post is to create an outline summary all the blogs from my Silverlight tips of the&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=155178" width="1" height="1"&gt;</description></item><item><title>Dew Drop - December 2, 2008 | Alvin Ashcraft's Morning Dew</title><link>http://blogs.silverlight.net/blogs/msnow/archive/2008/12/01/silverlight-tip-of-the-day-77-creating-an-efficient-random-generator.aspx#140917</link><pubDate>Tue, 02 Dec 2008 13:45:15 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:140917</guid><dc:creator>Dew Drop - December 2, 2008 | Alvin Ashcraft's Morning Dew</dc:creator><description>&lt;p&gt;Pingback from &amp;nbsp;Dew Drop - December 2, 2008 | Alvin Ashcraft's Morning Dew&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=140917" width="1" height="1"&gt;</description></item><item><title>2008 December 02 - Links for today &amp;laquo; My (almost) Daily Links</title><link>http://blogs.silverlight.net/blogs/msnow/archive/2008/12/01/silverlight-tip-of-the-day-77-creating-an-efficient-random-generator.aspx#140802</link><pubDate>Tue, 02 Dec 2008 10:12:18 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:140802</guid><dc:creator>2008 December 02 - Links for today « My (almost) Daily Links</dc:creator><description>&lt;p&gt;Pingback from &amp;nbsp;2008 December 02 - Links for today &amp;amp;laquo; My (almost) Daily Links&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=140802" width="1" height="1"&gt;</description></item><item><title>Silverlight Cream for December 01, 2008 -- #443</title><link>http://blogs.silverlight.net/blogs/msnow/archive/2008/12/01/silverlight-tip-of-the-day-77-creating-an-efficient-random-generator.aspx#140621</link><pubDate>Tue, 02 Dec 2008 06:20:36 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:140621</guid><dc:creator>Community Blogs</dc:creator><description>&lt;p&gt;In this issue: Alex Golesh, Silverlight SDK, John Stockton, Page Brooks(2), Mike Snow(2), Terence Tsang&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=140621" width="1" height="1"&gt;</description></item><item><title>re: Silverlight Tip of the Day #77 - Creating an Efficient Random Generator</title><link>http://blogs.silverlight.net/blogs/msnow/archive/2008/12/01/silverlight-tip-of-the-day-77-creating-an-efficient-random-generator.aspx#140480</link><pubDate>Tue, 02 Dec 2008 00:56:10 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:140480</guid><dc:creator>jackbond</dc:creator><description>&lt;p&gt;The differences are minor, but one of the primary ones is maintainability. First off, this functionality has nothing to do with the Application class itself, so why put it there and then require a cast? Or in the future, if he needed to refactor this code, and decided to put it in a library, he would need to update all the existing references. Better just to separate it out in the beginning (especially if it's going to encapsulate thread safetey as well.)&lt;/p&gt;
&lt;p&gt;Somewhat related, and not nearly emphasized enough:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://en.wikipedia.org/wiki/Law_of_Demeter"&gt;en.wikipedia.org/.../Law_of_Demeter&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=140480" width="1" height="1"&gt;</description></item><item><title>re: Silverlight Tip of the Day #77 - Creating an Efficient Random Generator</title><link>http://blogs.silverlight.net/blogs/msnow/archive/2008/12/01/silverlight-tip-of-the-day-77-creating-an-efficient-random-generator.aspx#140473</link><pubDate>Tue, 02 Dec 2008 00:16:47 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:140473</guid><dc:creator>miguelito928</dc:creator><description>&lt;p&gt;Mike,&lt;/p&gt;
&lt;p&gt;I expanded on your blog post with a few thoughts of my own on this subject. &amp;nbsp;See my blog post as a tribute to yours:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://murrayon.net/2008/12/correctly-using-random-number.html"&gt;murrayon.net/.../correctly-using-random-number.html&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=140473" width="1" height="1"&gt;</description></item><item><title>re: Silverlight Tip of the Day #77 - Creating an Efficient Random Generator</title><link>http://blogs.silverlight.net/blogs/msnow/archive/2008/12/01/silverlight-tip-of-the-day-77-creating-an-efficient-random-generator.aspx#140419</link><pubDate>Mon, 01 Dec 2008 22:42:23 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:140419</guid><dc:creator>mike.snow</dc:creator><description>&lt;p&gt;The main difference is that the class is static.&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=140419" width="1" height="1"&gt;</description></item><item><title>re: Silverlight Tip of the Day #77 - Creating an Efficient Random Generator</title><link>http://blogs.silverlight.net/blogs/msnow/archive/2008/12/01/silverlight-tip-of-the-day-77-creating-an-efficient-random-generator.aspx#140417</link><pubDate>Mon, 01 Dec 2008 22:32:54 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:140417</guid><dc:creator>GearWorld</dc:creator><description>&lt;p&gt;Waaaaa I don't get it. &amp;nbsp;I look at both code and I don't see any difference else then the name of the method and the name of the class&lt;/p&gt;
&lt;p&gt;Can you guys shed some light on it please ?&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=140417" width="1" height="1"&gt;</description></item><item><title>re: Silverlight Tip of the Day #77 - Creating an Efficient Random Generator</title><link>http://blogs.silverlight.net/blogs/msnow/archive/2008/12/01/silverlight-tip-of-the-day-77-creating-an-efficient-random-generator.aspx#140385</link><pubDate>Mon, 01 Dec 2008 22:11:47 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:140385</guid><dc:creator>mike.snow</dc:creator><description>&lt;p&gt;Good points! I will update the post to use a static method as you showed.&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=140385" width="1" height="1"&gt;</description></item><item><title>re: Silverlight Tip of the Day #77 - Creating an Efficient Random Generator</title><link>http://blogs.silverlight.net/blogs/msnow/archive/2008/12/01/silverlight-tip-of-the-day-77-creating-an-efficient-random-generator.aspx#140381</link><pubDate>Mon, 01 Dec 2008 22:08:03 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:140381</guid><dc:creator>Odegaard</dc:creator><description>&lt;p&gt;I couldn't agree more with JackBond. The pattern used above is horrible.&lt;/p&gt;
&lt;p&gt;Just to add to the above example. I would use lazy instantiation, as well as making sure it's thread safe (see &lt;a rel="nofollow" target="_new" href="http://en.csharp-online.net/Singleton_design_pattern:_Thread-safe_Singleton"&gt;en.csharp-online.net/Singleton_design_pattern:_Thread-safe_Singleton&lt;/a&gt;)&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=140381" width="1" height="1"&gt;</description></item><item><title>re: Silverlight Tip of the Day #77 - Creating an Efficient Random Generator</title><link>http://blogs.silverlight.net/blogs/msnow/archive/2008/12/01/silverlight-tip-of-the-day-77-creating-an-efficient-random-generator.aspx#140379</link><pubDate>Mon, 01 Dec 2008 21:52:57 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:140379</guid><dc:creator>jackbond</dc:creator><description>&lt;p&gt;You could avoid tying your code to a particular application class (and thereby the unneccessary casting) by simply using a static method on a utility class to achieve the same result (sample below) One other issue, the silverlight docs make no mention of whether Next() is thread safe or not. If not, it would be pretty easy to lock on the _Random object (another reason to put this functionality in a separate class)&lt;/p&gt;
&lt;p&gt;public class GlobalRandom&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;static Random _Random;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;static GlobalRandom()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;_Random = new Random();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public static int Next(int min, int max)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return _Random.Next(min, max);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=140379" width="1" height="1"&gt;</description></item><item><title>Silverlight Tip of the Day #77 - Creating an Efficient Random Generator</title><link>http://blogs.silverlight.net/blogs/msnow/archive/2008/12/01/silverlight-tip-of-the-day-77-creating-an-efficient-random-generator.aspx#140354</link><pubDate>Mon, 01 Dec 2008 20:58:32 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:140354</guid><dc:creator>Microsoft Weblogs</dc:creator><description>&lt;p&gt;In some of my older posts I was creating a separate random generator for each object. However, the documentation&lt;/p&gt;
&lt;img src="http://blogs.silverlight.net/aggbug.aspx?PostID=140354" width="1" height="1"&gt;</description></item></channel></rss>