Bug 26836 - Random Next returns sequences
Summary: Random Next returns sequences
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 3.12.0
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-02-07 23:58 UTC by blaize
Modified: 2015-02-24 20:24 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 26836 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description blaize 2015-02-07 23:58:46 UTC
using System;

namespace TestRNG
    class MainClass
        public static void Main (string[] args)
            Random r = new Random (Guid.NewGuid().ToByteArray()[0]);
            for (int i = 0; i < 20; i++) {
                int rn = r.Next ();
                Console.WriteLine(rn + " " + (rn % 2));

Always returns the same set of values for (rn % 2) even though rn is different.  These values are the same as Random(0, 2) returns.  I get these values: 00111111110110001001.

bolt:~$ mono --version
Mono JIT compiler version 3.12.0 (tarball Mon Jan 19 14:55:43 UTC 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	LLVM:          supported, not enabled.
	GC:            sgen
bolt:~$ uname -a 
Linux bolt 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

I know we used to see this kind of thing with taking rand() in c modulus some number, in the old days... but I would have thought that we were beyond that now.  Certainly the source looks to be implementing something more sophisticated.
Comment 1 blaize 2015-02-24 20:24:47 UTC
Note that this is also the case for 

Random r = new Random ();