summaryrefslogtreecommitdiff
path: root/storage/innobase/include/ut0rnd.h
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2019-12-09 12:17:12 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2019-12-10 16:58:28 +0200
commit51fc8ab73e3ee9712d1128fefc9831dcf891a3b5 (patch)
tree0c6eaa9608129cc440535b2be77f8c6bc71323ae /storage/innobase/include/ut0rnd.h
parent4c0854f2211a034683afd3a2c1e4f8d020c6785a (diff)
downloadmariadb-git-51fc8ab73e3ee9712d1128fefc9831dcf891a3b5.tar.gz
MDEV-21256: Reduce the use of ut_rnd_gen_next_ulint()
ut_rnd_set_seed(): Unused function; remove. ut_rnd_gen(): Renamed from page_cur_lcg_prng(). ut_rnd_current: The internal state of ut_rnd_gen(). page_cur_open_on_rnd_user_rec(): Replace linear search with page_rec_get_nth().
Diffstat (limited to 'storage/innobase/include/ut0rnd.h')
-rw-r--r--storage/innobase/include/ut0rnd.h54
1 files changed, 26 insertions, 28 deletions
diff --git a/storage/innobase/include/ut0rnd.h b/storage/innobase/include/ut0rnd.h
index b6d4d4abbd2..56b4a6159c1 100644
--- a/storage/innobase/include/ut0rnd.h
+++ b/storage/innobase/include/ut0rnd.h
@@ -1,6 +1,7 @@
/*****************************************************************************
Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -27,38 +28,35 @@ Created 1/20/1994 Heikki Tuuri
#define ut0rnd_h
#include "ut0byte.h"
+#include <my_sys.h>
#ifndef UNIV_INNOCHECKSUM
-/** The 'character code' for end of field or string (used
-in folding records */
-#define UT_END_OF_FIELD 257
+/** Seed value of ut_rnd_gen() */
+extern uint64_t ut_rnd_current;
+
+/** @return a pseudo-random 64-bit number */
+inline uint64_t ut_rnd_gen()
+{
+ /*
+ This is a linear congruential pseudo random number generator.
+ The formula and the constants
+ being used are:
+ X[n+1] = (a * X[n] + c) mod m
+ where:
+ X[0] = my_interval_timer()
+ a = 1103515245 (3^5 * 5 * 7 * 129749)
+ c = 12345 (3 * 5 * 823)
+ m = 18446744073709551616 (1<<64), implicit */
+
+ if (UNIV_UNLIKELY(!ut_rnd_current)) {
+ ut_rnd_current = my_interval_timer();
+ }
+
+ ut_rnd_current = 1103515245 * ut_rnd_current + 12345;
+ return ut_rnd_current;
+}
/********************************************************//**
-This is used to set the random number seed. */
-UNIV_INLINE
-void
-ut_rnd_set_seed(
-/*============*/
- ulint seed); /*!< in: seed */
-/********************************************************//**
-The following function generates a series of 'random' ulint integers.
-@return the next 'random' number */
-UNIV_INLINE
-ulint
-ut_rnd_gen_next_ulint(
-/*==================*/
- ulint rnd); /*!< in: the previous random number value */
-/*********************************************************//**
-The following function generates 'random' ulint integers which
-enumerate the value space (let there be N of them) of ulint integers
-in a pseudo-random fashion. Note that the same integer is repeated
-always after N calls to the generator.
-@return the 'random' number */
-UNIV_INLINE
-ulint
-ut_rnd_gen_ulint(void);
-/*==================*/
-/********************************************************//**
Generates a random integer from a given interval.
@return the 'random' number */
UNIV_INLINE