Bug 16928 - Random does crash when minimum is set to 0
Summary: Random does crash when minimum is set to 0
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.10.0.x
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2013-12-21 07:24 UTC by Stefan Schoeb
Modified: 2013-12-30 05:13 UTC (History)
2 users (show)

Tags:
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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Stefan Schoeb 2013-12-21 07:24:07 UTC
Following code:

var rand = new Random();
rand.next(0);

does work in a windows .NET 4.5 console application and does crash when executing on Xamarin.Droid with a DivisionByZeroException.

I would expect to get "0" here as well.
Comment 1 Mohit Kheterpal 2013-12-23 07:11:18 UTC
Today we have tried to reproduce this issue, however we are not able to reproduce it. We have used the below code :

var rand = new Random();
Console.WriteLine("Random number is :"+rand.Next(0));

Screencast : http://screencast.com/t/TUlR200bAh

Could you please provide us small sample project? So that we can reproduce this issue.
Comment 2 Stefan Schoeb 2013-12-23 07:23:38 UTC
Here is a sample project:
https://github.com/sschoeb/bug16928

Here is the complete error message:
An unhandled exception occured.
12-23 13:17:22.093 I/MonoDroid(13912): UNHANDLED EXCEPTION: System.DivideByZeroException: Division by zero
12-23 13:17:22.093 I/MonoDroid(13912): at (wrapper managed-to-native) object.__icall_wrapper___emul_lrem (long,long) <0x00043>
12-23 13:17:22.093 I/MonoDroid(13912): at System.Random.Next (int) <IL 0x0001b, 0x000cb>
12-23 13:17:22.093 I/MonoDroid(13912): at AndroidApplication1.Activity1.OnCreate (Android.OS.Bundle) [0x00051] in c:\Projects\ACS\AndroidApplication1\AndroidApplication1\Activity1.cs:31
12-23 13:17:22.093 I/MonoDroid(13912): at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.10.1-branch/d23a19bf/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.App.Activity.cs:1559
12-23 13:17:22.093 I/MonoDroid(13912): at (wrapper dynamic-method) object.cc3dd0c7-ce55-4a07-b9b2-3f50513d7074 (intptr,intptr,intptr) <IL 0x00017, 0x00043>
Unhandled Exception:

System.DivideByZeroException: Division by zero
12-23 13:17:39.493 E/mono    (13912): 
In mgmain JNI_OnLoad
12-23 13:17:39.493 E/mono    (13912): Unhandled Exception:
12-23 13:17:39.493 E/mono    (13912): System.DivideByZeroException: Division by zero
12-23 13:17:39.493 E/mono-rt (13912):  12-23 13:17:39.493 E/mono    (13912):   at (wrapper managed-to-native) object:__icall_wrapper___emul_lrem (long,long)
12-23 13:17:39.493 E/mono    (13912):   at System.Random.Next (Int32 maxValue) [0x00000] in <filename unknown>:0 
12-23 13:17:39.493 E/mono    (13912):   at AndroidApplication1.Activity1.OnCreate (Android.OS.Bundle bundle) [0x00051] in c:\Projects\ACS\AndroidApplication1\AndroidApplication1\Activity1.cs:31 
12-23 13:17:39.493 E/mono    (13912):   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.10.1-branch/d23a19bf/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.App.Activity.cs:1559 
12-23 13:17:39.493 E/mono    (13912):   at (wrapper dynamic-method) object:cc3dd0c7-ce55-4a07-b9b2-3f50513d7074 (intptr,intptr,intptr)
12-23 13:17:39.493 E/mono-rt (13912): [ERROR] FATAL UNHANDLED EXCEPTION: System.DivideByZeroException: Division by zero
12-23 13:17:39.493 E/mono-rt (13912):   at (wrapper managed-to-native) object:__icall_wrapper___emul_lrem (long,long)
12-23 13:17:39.493 E/mono-rt (13912):   at System.Random.Next (Int32 maxValue) [0x00000] in <filename unknown>:0 
12-23 13:17:39.493 E/mono-rt (13912):   at AndroidApplication1.Activity1.OnCreate (Android.OS.Bundle bundle) [0x00051] in c:\Projects\ACS\AndroidApplication1\AndroidApplication1\Activity1.cs:31 
12-23 13:17:39.493 E/mono-rt (13912):   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.10.1-branch/d23a19bf/source/monodroid/src/Mono.Android/platforms/android-8/src/generated/Android.App.Activity.cs:1559 
12-23 13:17:39.493 E/mono-rt (13912):   at (wrapper dynamic-method) object:cc3dd0c7-ce55-4a07-b9b2-3f50513d7074 (intptr,intptr,intptr)
The program 'Mono' has exited with code 0 (0x0).


Here a view more informations about my environment:
- Visual Studio 2012 Update 3
- Win 8
- Xamarin.Android 4.10.01073
- Xamarin.iOS 1.8.365
Comment 3 Jonathan Pryor 2013-12-26 10:43:17 UTC
Please try with the Xamarin.Android 4.11 alpha release, which has an updated BCL.
Comment 4 Stefan Schoeb 2013-12-26 16:48:16 UTC
Works fine with latest alpha! Thanks!
Comment 5 Mohit Kheterpal 2013-12-30 05:13:17 UTC
As per comment 4, this issue is working fine now.

Hence closing this issue