delete: $/Dev10/feature/vs_langs01_s/Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/kernel/srand_tags.txt;C1086571
File: srand_tags.txt
===================================================================
--- $/Dev10/feature/vs_langs01_s/Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/ironruby-tags/core/kernel/srand_tags.txt;C1086571  (server)    11/15/2009 1:14 AM
+++ [no target file]
@@ -1,2 +1,0 @@
-fails:Kernel.srand defaults number to a random value
-fails:Kernel.srand calls #to_i on number
===================================================================
edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;C1244922
File: Initializers.Generated.cs
===================================================================
--- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;C1244922  (server)    11/15/2009 1:41 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;regex
@@ -3084,6 +3084,7 @@
             );
             
             DefineLibraryMethod(module, "srand", 0x52, 
+                new Func<IronRuby.Runtime.RubyContext, System.Object, System.Object>(IronRuby.Builtins.KernelOps.SeedRandomNumberGenerator), 
                 new Func<IronRuby.Runtime.RubyContext, System.Object, IronRuby.Runtime.IntegerValue, System.Object>(IronRuby.Builtins.KernelOps.SeedRandomNumberGenerator)
             );
             
@@ -3348,6 +3349,7 @@
             );
             
             DefineLibraryMethod(module, "srand", 0x61, 
+                new Func<IronRuby.Runtime.RubyContext, System.Object, System.Object>(IronRuby.Builtins.KernelOps.SeedRandomNumberGenerator), 
                 new Func<IronRuby.Runtime.RubyContext, System.Object, IronRuby.Runtime.IntegerValue, System.Object>(IronRuby.Builtins.KernelOps.SeedRandomNumberGenerator)
             );
             
===================================================================
edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs;C1221149
File: KernelOps.cs
===================================================================
--- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs;C1221149  (server)    11/15/2009 1:13 AM
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs;regex
@@ -21,6 +21,7 @@
 using System.Reflection;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
+using System.Security.Cryptography;
 using System.Threading;
 using IronRuby.Compiler;
 using IronRuby.Runtime;
@@ -1564,8 +1565,28 @@
 
         #region rand, srand
 
+        private static RNGCryptoServiceProvider _RNGCryptoServiceProvider;
+
         [RubyMethod("srand", RubyMethodAttributes.PrivateInstance)]
         [RubyMethod("srand", RubyMethodAttributes.PublicSingleton)]
+        public static object SeedRandomNumberGenerator(RubyContext/*!*/ context, object self) {
+            // This should use a combination of the time, the process id, and a sequence number.
+
+            if (_RNGCryptoServiceProvider == null) {
+                _RNGCryptoServiceProvider = new RNGCryptoServiceProvider();
+            }
+
+            int secureRandomNumber = 0;
+            do {
+                byte[] b = new byte[4];
+                _RNGCryptoServiceProvider.GetBytes(b);
+                secureRandomNumber = ((int)b[0] << 24) | ((int)b[1] << 16) | ((int)b[2] << 8) | b[3];
+            } while (secureRandomNumber == 0); // GetNonZeroBytes does not exist in Silverlight
+            return SeedRandomNumberGenerator(context, self, secureRandomNumber);
+        }
+
+        [RubyMethod("srand", RubyMethodAttributes.PrivateInstance)]
+        [RubyMethod("srand", RubyMethodAttributes.PublicSingleton)]
         public static object SeedRandomNumberGenerator(RubyContext/*!*/ context, object self, [DefaultProtocol]IntegerValue seed) {
             object result = context.RandomNumberGeneratorSeed;
             context.SeedRandomNumberGenerator(seed);
===================================================================
edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/MutableStringOps.cs;C1240182
File: MutableStringOps.cs
===================================================================
--- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/MutableStringOps.cs;C1240182  (server)    11/16/2009 11:05 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/MutableStringOps.cs;regex
@@ -1849,7 +1849,7 @@
 
         [RubyMethod("scan")]
         public static RubyArray/*!*/ Scan(RubyScope/*!*/ scope, MutableString/*!*/ self, [DefaultProtocol, NotNull]RubyRegex/*!*/ regex) {
-            IList<MatchData> matches = regex.Matches(scope.RubyContext.KCode, self);
+            IList<MatchData> matches = regex.Matches(scope.RubyContext.KCode, self, false);
 
             var matchScope = scope.GetInnerMostClosureScope();
             
===================================================================
edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Builtins/MatchData.cs;C1233815
File: MatchData.cs
===================================================================
--- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Builtins/MatchData.cs;C1233815  (server)    11/12/2009 10:50 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Builtins/MatchData.cs;regex
@@ -58,7 +58,8 @@
             _match = match;
 
             // TODO (opt): create groups instead?
-            _originalString = originalString.Clone().Freeze();
+            // Debug.Assert(originalString.IsFrozen);
+            _originalString = originalString;
 
             _kIndices = kIndices;
             IsTainted = originalString.IsTainted;
@@ -89,7 +90,7 @@
             _originalString = other._originalString;
         }
 
-        internal static MatchData Create(Match/*!*/ match, MutableString/*!*/ input, string/*!*/ encodedInput, RubyEncoding kcoding, int kStart) {
+        internal static MatchData Create(Match/*!*/ match, MutableString/*!*/ input, bool inputMayMutate, string/*!*/ encodedInput, RubyEncoding kcoding, int kStart) {
             if (!match.Success) {
                 return null;
             }
@@ -113,6 +114,9 @@
                 kIndices = null;
             }
 
+            if (inputMayMutate) {
+                input = input.Clone().Freeze();
+            }
             return new MatchData(match, input, kIndices);
         }
         
===================================================================
edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyRegex.cs;C1200585
File: RubyRegex.cs
===================================================================
--- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyRegex.cs;C1200585  (server)    11/12/2009 10:51 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubyRegex.cs;regex
@@ -225,7 +225,7 @@
 
         public MatchData Match(RubyEncoding kcode, MutableString/*!*/ input) {
             string str;
-            return MatchData.Create(Transform(ref kcode, input, 0, out str).Match(str), input, str, kcode, 0);
+            return MatchData.Create(Transform(ref kcode, input, 0, out str).Match(str), input, true, str, kcode, 0);
         }
 
         /// <summary>
@@ -251,7 +251,7 @@
                 match = regex.Match(str, start);
             }
 
-            return MatchData.Create(match, input, str, kcode, start);
+            return MatchData.Create(match, input, true, str, kcode, start);
         }
 
         public MatchData LastMatch(RubyEncoding kcode, MutableString/*!*/ input) {
@@ -298,7 +298,7 @@
                     return null;
                 }
             }
-            return MatchData.Create(match, input, str, kcode, 0);
+            return MatchData.Create(match, input, true, str, kcode, 0);
         }
 
         /// <summary>
@@ -326,17 +326,27 @@
         /// <summary>
         /// Returns a collection of fresh MatchData objects.
         /// </summary>
-        public IList<MatchData>/*!*/ Matches(RubyEncoding kcode, MutableString/*!*/ input) {
+        public IList<MatchData>/*!*/ Matches(RubyEncoding kcode, MutableString/*!*/ input, bool inputMayMutate) {
             string str;
             MatchCollection matches = Transform(ref kcode, input, 0, out str).Matches(str);
 
             var result = new MatchData[matches.Count];
+            if (result.Length > 0 && inputMayMutate) {
+                // clone and freeze the string once so that it can be shared by all the MatchData objects
+                input = input.Clone().Freeze();
+            }
+
             for (int i = 0; i < result.Length; i++) {
-                result[i] = MatchData.Create(matches[i], input, str, kcode, 0);
+                result[i] = MatchData.Create(matches[i], input, false, str, kcode, 0);
             }
+
             return result;
         }
 
+        public IList<MatchData>/*!*/ Matches(RubyEncoding kcode, MutableString/*!*/ input) {
+            return Matches(kcode, input, true);
+        }
+
         public MutableString[]/*!*/ Split(RubyEncoding kcode, MutableString/*!*/ input) {
             string str;
             return MutableString.MakeArray(Transform(ref kcode, input, 0, out str).Split(str), kcode ?? input.Encoding);
===================================================================
