ustring uLF (CharConst ("\n"));
ustring uCRLF (CharConst ("\r\n"));
ustring uSPC (CharConst (" "));
-ustring uR (CharConst ("R"));
+ustring uR (CharConst ("_R"));
ustring uDash (CharConst ("-"));
ustring uSlash (CharConst ("/"));
//ustring uSlash2 (CharConst ("//"));
static int Inited = 0;
static unsigned long Seed;
-static ustring RChar (CharConst ("ABCDEFGHJKLMNPQRTUVWXYZabcdefghijkmnopqrstuvwxyz23456789"));
+//static ustring RChar (CharConst ("ABCDEFGHJKLMNPQRTUVWXYZabcdefghijkmnopqrstuvwxyz23456789"));
static ustring SaltChar (CharConst ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"));
static void init () {
static void enc (unsigned long v, char* b) {
int i;
- int n = RChar.size ();
+// int n = RChar.size ();
+ int n = SaltChar.size ();
for (i = 0; i < 5; i ++) {
- b[i] = RChar[v % n];
+// b[i] = RChar[v % n];
+ b[i] = SaltChar[v % n];
v /= n;
}
}
-#if 0
-ustring randomKey () {
- char b[128];
- ustring ans;
- ssize_t s;
-
- if (! Inited)
- init ();
- s = snprintf (b, 128, "%.8x%.8x%.8x%.8x", random (), random (), random (), random ());
- ans = ustring (b, s);
- return ans;
-}
-#endif
-#if 0
-ustring smallRandomKey () {
- char b[128];
- ustring ans;
- ssize_t s;
-
- if (! Inited)
- init ();
- s = snprintf (b, 128, "%.8x%.8x", random (), random ());
- ans = ustring (b, s);
- return ans;
-}
-#endif
-
ustring randomKey () {
char b[32];
b[11] = '$';
return ustring (b, 12);
}
+
+double randDouble () {
+ if (! Inited)
+ init ();
+ return random () / double (0x80000000UL);
+}
ustring randomKey (unsigned long n);
ustring smallRandomKey ();
ustring makeSalt ();
+double randDouble ();
#endif /* UTIL_RANDOM_H */
return NULL;
}
+/*DOC:
+====delete====
+ (delete KEY) -> NIL
+
+*/
+//#SFUNC delete ml_db_x_delete $db-rw
+MNode* ml_db_x_delete (MNode* cell, MlEnv* mlenv, MLFunc* mobj) {
+ MNode* arg = cell->cdr ();
+ MLDb* obj = MObjRef<MLDb> (mobj, cMLDbID);
+ ustring key;
+
+ if (!arg)
+ throw (uErrorWrongNumber);
+ key = eval_str (arg->car (), mlenv);
+ nextNode (arg);
+ if (arg)
+ throw (uErrorWrongNumber);
+
+ obj->db.del (key);
+
+ return NULL;
+}
+
static void set_read_vars (ustring& val, std::vector<ustring>& vars, std::vector<int>& type, MlEnv* mlenv) {
if (vars.size () > 0) {
uiterator b = val.begin ();
MNode* ml_db_rw (MNode* cell, MlEnv* mlenv);
MNode* ml_db_x_read (MNode* cell, MlEnv* mlenv, MLFunc* mobj);
MNode* ml_db_x_write (MNode* cell, MlEnv* mlenv, MLFunc* mobj);
+MNode* ml_db_x_delete (MNode* cell, MlEnv* mlenv, MLFunc* mobj);
MNode* ml_db_x_read_array (MNode* cell, MlEnv* mlenv, MLFunc* mobj);
MNode* ml_db_x_write_array (MNode* cell, MlEnv* mlenv, MLFunc* mobj);
MNode* ml_db_x_select (MNode* cell, MlEnv* mlenv, MLFunc* mobj);
#include "motorenv.h"
#include "expr.h"
#include "util_const.h"
+#include "util_random.h"
#include <exception>
#include <math.h>
double v = arg1_double (cell, mlenv);
return newMNode_num (v - floor (v));
}
+
+/*DOC:
+===random===
+ (random) -> NUMBER
+
+*/
+//#AFUNC random ml_random
+//#WIKIFUNC random ml_random
+MNode* ml_random (MNode* cell, MlEnv* mlenv) {
+ MNode* arg = cell->cdr ();
+
+ if (arg)
+ throw (uErrorWrongNumber);
+
+ return newMNode_num (randDouble ());
+}
MNode* ml_ceil (MNode* cell, MlEnv* mlenv);
MNode* ml_floor (MNode* cell, MlEnv* mlenv);
MNode* ml_fraction (MNode* cell, MlEnv* mlenv);
+MNode* ml_random (MNode* cell, MlEnv* mlenv);
#endif /* ML_MATH_H */
#include "motorenv.h"
#include "motoroutput.h"
#include "util_const.h"
+#include "util_random.h"
#include "util_string.h"
#include "expr.h"
#include "utf8.h"
return newMNode_str (new ustring (formatString (format, par)));
}
+
+/*DOC:
+===random-key===
+ (random-key) -> STRING
+
+*/
+//#AFUNC random-key ml_random_key
+//#WIKIFUNC random-key ml_random_key
+MNode* ml_random_key (MNode* cell, MlEnv* mlenv) {
+ MNode* arg = cell->cdr ();
+
+ if (arg)
+ throw (uErrorWrongNumber);
+
+ return newMNode_str (new ustring (randomKey ()));
+}
MNode* ml_pad0 (MNode* cell, MlEnv* mlenv);
MNode* ml_ellipsis (MNode* cell, MlEnv* mlenv);
MNode* ml_string_format (MNode* cell, MlEnv* mlenv);
+MNode* ml_random_key (MNode* cell, MlEnv* mlenv);
#endif /* ML_STRING_H */