elementary_functions: fix rand() with a single key letter after 02f1f9cd 25/21725/4
Clément David [Tue, 6 Apr 2021 09:14:28 +0000 (11:14 +0200)]
Change-Id: I7a57b563875025b366cc5c96df93706356b155a3

scilab/modules/elementary_functions/help/en_US/elementarymatrices/random/rand.xml
scilab/modules/elementary_functions/help/ru_RU/elementarymatrices/random/rand.xml
scilab/modules/elementary_functions/sci_gateway/cpp/sci_rand.cpp

index 9834aad..25e0851 100644 (file)
                 <listitem>
                     <para>
                         a string, the distribution of random numbers (default  <literal>key="uniform" </literal>).
-                        The available values are <literal>"uniform"</literal> and
-                        <literal>"normal"</literal>.
+                        The possible values are:
+                        <itemizedlist>
+                        <listitem>
+                        <literal>"uniform"</literal> or <literal>"u"</literal>
+                        </listitem>
+                        <listitem>
+                        <literal>"normal"</literal> or <literal>"n"</literal>
+                        </listitem>
+                        </itemizedlist>
                     </para>
                 </listitem>
             </varlistentry>
         </para>
         <variablelist>
             <varlistentry>
-                <term>rand("uniform")</term>
+                <term>rand("uniform") or rand("u")</term>
                 <listitem>
                     <para>
                         sets the generator to a uniform random number
                 </listitem>
             </varlistentry>
             <varlistentry>
-                <term>rand("normal")</term>
+                <term>rand("normal") or rand("n")</term>
                 <listitem>
                     <para>
                         sets the generator to a normal (Gauss-Laplace) random number generator,
index 914d890..05f44bd 100644 (file)
                 <listitem>
                     <para>
                         строка, распределение случайных чисел (по умолчанию
-                        <literal>key="uniform"</literal>). Доступными значениями являются
-                        <literal>"uniform"</literal> (равновероятный) и <literal>"normal"</literal>
-                        (нормальный).
+                        <literal>key="uniform"</literal>). Доступными значениями являются:
+                        <itemizedlist>
+                        <listitem>
+                        <literal>"uniform"</literal> (равновероятный) или <literal>"u"</literal>
+                        </listitem>
+                        <listitem>
+                        <literal>"normal"</literal> (нормальный) или <literal>"n"</literal>
+                        </listitem>
+                        </itemizedlist>
                     </para>
                 </listitem>
             </varlistentry>
index b4090ad..f554d1f 100644 (file)
@@ -261,10 +261,22 @@ int setRandType(const wchar_t* _wcType)
     {
         return 0;
     }
-    else if (!wcscmp(_wcType,g_pwstTypeNormal))
+    if (!wcscmp(_wcType,g_pwstTypeNormal))
     {
         return 1;
     }
+
+    // shortcut version
+    if (_wcType[0] == g_pwstTypeUniform[0] && _wcType[1] == L'\0')
+    {
+        return 0;
+    }
+    if (_wcType[0] == g_pwstTypeNormal[0] && _wcType[1] == L'\0')
+    {
+        return 1;
+    }
+
+    // invalid key
     return -1;
 }
 /*--------------------------------------------------------------------------*/