![]() |
Statistics for MySQL
0.9
|
00001 /* rand_mt.cc (rand_mt) */ 00002 00003 /*********************************************************************** 00004 * This code is part of Statistics for MySQL. 00005 * 00006 * Copyright (C) 2011 Heinrich Schuchardt (xypron.glpk@gmx.de) 00007 * 00008 * Licensed under the Apache License, Version 2.0 (the "License"); 00009 * you may not use this file except in compliance with the License. 00010 * You may obtain a copy of the License at 00011 * 00012 * http://www.apache.org/licenses/LICENSE-2.0 00013 * 00014 * Unless required by applicable law or agreed to in writing, software 00015 * distributed under the License is distributed on an "AS IS" BASIS, 00016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00017 * See the License for the specific language governing permissions and 00018 * limitations under the License. 00019 ***********************************************************************/ 00020 00032 #include "sqlstat.h" 00033 #include "sqlrand.h" 00034 00035 using sqlstat::MersenneTwister; 00036 00048 my_bool rand_mt_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { 00049 00050 if (!sqlstat_plugin_isloaded()) { 00051 strcpy(message,"libsqlstat plugin is not loaded. " 00052 "Use 'INSTALL PLUGIN' for installation."); 00053 return 1; 00054 } 00055 00056 if (args->arg_count != 0) { 00057 strcpy(message,"rand_mt() requires no argument"); 00058 return 1; 00059 } 00060 00061 initid->maybe_null = 0; 00062 initid->decimals = NOT_FIXED_DEC; 00063 initid->max_length = 13 + initid->decimals; 00064 initid->ptr = NULL; 00065 initid->const_item = 0; 00066 return 0; 00067 } 00068 00081 double rand_mt(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) { 00082 return MersenneTwister::nextDouble(); 00083 } 00084 00092 void rand_mt_deinit(UDF_INIT *initid) { 00093 return; 00094 }