* [#10465](https://bugzilla.scilab.org/10465): At Scilab exit, the help browser is not saved nor restored.
* [#10476](https://bugzilla.scilab.org/10476): From `browsevar`, displaying the content of lists, structures, cells, or other custom tlists or mlists was not possible.
* [#10490](https://bugzilla.scilab.org/10490): The `mapsound` page was poor with a single interesting example.
+* [#11600](https://bugzilla.scilab.org/11600): `rand()` was parsing its inputs incorrectly.
* [#11677](https://bugzilla.scilab.org/11677): The original Arnoldi functions were obsolete.
* [#12418](https://bugzilla.scilab.org/12418): Using bvode() with "continuation", i.e. `ipar(9) > 1` led to an error.
* [#12516](https://bugzilla.scilab.org/12516): From `browsevar`, clicking on any graphical handle did not edit its figure with `ged`.
#include "basic_functions.h"
}
-const wchar_t g_pwstConfigInfo[] = {L"info"};
-const wchar_t g_pwstConfigSeed[] = {L"seed"};
+const wchar_t g_pwstConfigInfo[] = L"info";
+const wchar_t g_pwstConfigSeed[] = L"seed";
-const wchar_t g_pwstTypeUniform[] = {L"uniform"};
-const wchar_t g_pwstTypeNormal[] = {L"normal"};
+const wchar_t g_pwstTypeUniform[] = L"uniform";
+const wchar_t g_pwstTypeNormal[] = L"normal";
-int setRandType(wchar_t _wcType);
+int setRandType(const wchar_t* _wcType);
double getNextRandValue(int _iRandType, int* _piRandSave, int _iForceInit);
/*
wchar_t* pwstKey = pS->get(0);
- if (pwstKey[0] == g_pwstConfigInfo[0])
+ if (!wcscmp(pwstKey,g_pwstConfigInfo))
{
//info
if (iSizeIn > 1)
out.push_back(new types::String(g_pwstTypeNormal));
}
}
- else if (pwstKey[0] == g_pwstConfigSeed[0])
+ else if (!wcscmp(pwstKey,g_pwstConfigSeed))
{
//seed
if (iSizeIn == 1)
}
else
{
- siRandType = setRandType(pwstKey[0]);
+ int iRandSave = siRandType;
+ if (iSizeIn > 1)
+ {
+ Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "rand", 1);
+ return types::Function::Error;
+ }
+ siRandType = setRandType(pwstKey);
+ if (siRandType < 0)
+ {
+ siRandType = iRandSave;
+ Scierror(999, _("%s: Wrong value for input argument #%d: '%s', '%s', '%s' or '%s' expected.\n"), "rand", 1,"info","seed","uniform","normal");
+ return types::Function::Error;
+ }
}
}
else
}
//set randomize law
- iRandSave = siRandType;
- siRandType = setRandType(pS->get(0)[0]);
+ siRandType = setRandType(pS->get(0));
+ if (siRandType < 0)
+ {
+ siRandType = iRandSave;
+ Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), "rand", iSizeIn,"uniform","normal");
+ return types::Function::Error;
+ }
+
iSizeIn--;
}
return dblVal;
}
-int setRandType(wchar_t _wcType)
+int setRandType(const wchar_t* _wcType)
{
- if (_wcType == L'g' || _wcType == L'n')
+ if (!wcscmp(_wcType,g_pwstTypeUniform))
+ {
+ return 0;
+ }
+ else if (!wcscmp(_wcType,g_pwstTypeNormal))
{
return 1;
}
- return 0;
+ return -1;
}
/*--------------------------------------------------------------------------*/
+
--- /dev/null
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2021 - Stéphane MOTTELET
+//
+// This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- CLI SHELL MODE -->
+// <-- NO CHECK REF -->
+//
+// <-- Non-regression test for bug 11600 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/11600
+//
+// <-- Short Description -->
+// rand("foo") runs silently without returning an error
+
+cmd = "rand(""foo"")";
+msg = msprintf(_("%s: Wrong value for input argument #%d: ''%s'', ''%s'', ''%s'' or ''%s'' expected.\n"), "rand", 1,"info","seed","uniform","normal");
+assert_checkerror(cmd,msg)
+
+cmd = "rand(2,2,""foo"")";
+msg = msprintf(_("%s: Wrong value for input argument #%d: ''%s'' or ''%s'' expected.\n"), "rand", 3, "uniform","normal");
+assert_checkerror(cmd,msg)
+
+cmd = "rand(2,""foo"")";
+msg = msprintf(_("%s: Wrong value for input argument #%d: ''%s'' or ''%s'' expected.\n"), "rand", 2, "uniform","normal");
+assert_checkerror(cmd,msg)