mtlb_rand was affected by the random rule.
For example, it used the 'normal' rule if rand("normal") had been set.
Change-Id: I5b3976324065b38255c41ec6a6f82c5c065717c0
* Bug #8031 fixed - cdfgam error message fixed.
+* Bug #8337 fixed - mtlb_rand now uses the "uniform" rule, whatever the random rule set is.
+
* Bug #11571 fixed - x_mdialog did not let the Look&Feel select the window size.
* Bug #11680 fixed - GUI functions in Scilab 5.4.X were much slower than in Scilab 5.3.3.
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
-function r=mtlb_rand(a)
+function r = mtlb_rand(a)
// Emulation function for rand() Matlab function
+ // Save current mode for random generator
+ randType = rand("info");
+ // Switch to uniform distribution
+ rand("uniform");
+
if and(size(a)==[1 1]) then
- r=rand(a,a)
+ r = rand(a, a)
else
- tmp=list()
+ tmp = list()
for k=1:size(a,"*")
- tmp(k)=a(k)
+ tmp(k) = a(k)
end
- r=rand(tmp(1:$))
+ r = rand(tmp(1:$))
end
+
+ // Restore rand mode
+ rand(randType);
+
endfunction
--- /dev/null
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+// This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+// <-- Non-regression test for bug 8337 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=8337
+//
+// <-- Short Description -->
+// mtlb_rand() was affected by the seed of rand(), whereas it follow the uniform rule,
+// as long as we don't have the 'rng' Matlab function to control the generation of random numbers.
+rand("normal");
+a = mtlb_rand(1000);
+assert_checktrue(and(a>=0 & a<=1));
+assert_checkequal(rand("info"), "normal");
--- /dev/null
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+// This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- CLI SHELL MODE -->
+
+// <-- Non-regression test for bug 8337 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=8337
+//
+// <-- Short Description -->
+// mtlb_rand() was affected by the seed of rand(), whereas it follow the uniform rule,
+// as long as we don't have the 'rng' Matlab function to control the generation of random numbers.
+
+rand("normal");
+a = mtlb_rand(1000);
+
+assert_checktrue(and(a>=0 & a<=1));
+assert_checkequal(rand("info"), "normal");