From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/70 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: Completeness status of musl Date: Thu, 23 Jun 2011 16:16:08 +0200 Message-ID: <20110623141608.GP27421@port70.net> References: <4DE277DF.3020605@int3.at> <4DE28333.9040900@int3.at> <20110529180854.GC6142@port70.net> <20110530103009.GE6142@port70.net> <20110530154741.GB277@brightrain.aerifal.cx> <20110530172735.GF6142@port70.net> <20110608235810.GJ191@brightrain.aerifal.cx> <20110621014640.GL27421@port70.net> <20110623065452.GU12592@brightrain.aerifal.cx> <20110623132517.GO27421@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="8vCeF2GUdMpe9ZbK" X-Trace: dough.gmane.org 1308838601 26834 80.91.229.12 (23 Jun 2011 14:16:41 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 23 Jun 2011 14:16:41 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-154-gllmg-musl=m.gmane.org@lists.openwall.com Thu Jun 23 16:16:36 2011 Return-path: Envelope-to: gllmg-musl@lo.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by lo.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1QZkhs-0004VI-35 for gllmg-musl@lo.gmane.org; Thu, 23 Jun 2011 16:16:32 +0200 Original-Received: (qmail 16187 invoked by uid 550); 23 Jun 2011 14:16:30 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 16179 invoked from network); 23 Jun 2011 14:16:30 -0000 Content-Disposition: inline In-Reply-To: <20110623132517.GO27421@port70.net> User-Agent: Mutt/1.5.20 (2009-06-14) Xref: news.gmane.org gmane.linux.lib.musl.general:70 Archived-At: --8vCeF2GUdMpe9ZbK Content-Type: text/plain; charset=us-ascii Content-Disposition: inline modified a bit to use uint32_t and uint64_t --8vCeF2GUdMpe9ZbK Content-Type: text/x-csrc; charset=us-ascii Content-Disposition: attachment; filename="random.c" #include #include static uint32_t init[] = { 0x00000000,0x991539b1,0x16a5bce3,0x6774a4cd, 0x3e01511e,0x4e508aaa,0x61048c05,0xf5500617, 0x846b7115,0x6a19892c,0x896a97af,0xdb48f936, 0x14898454,0x37ffd106,0xb58bff9c,0x59e17104, 0xcf918a49,0x09378c83,0x52c7a471,0x8d293ea9, 0x1f4fc301,0xc3db71be,0x39b44e1c,0xf8a44ef9, 0x4c8b80b1,0x19edc328,0x87bf4bdd,0xc9b240e5, 0xe9ee4b1b,0x4382aee7,0x535b6b41,0xf3bec5da}; static int n = 31; static int i = 3; static int j = 0; static uint32_t *x = init+1; static uint32_t lcg(uint32_t x) { return (1103515245*x + 12345) & 0x7fffffff; } static uint32_t parkmiller(uint32_t x) { return (uint64_t)16807*x % 0x7fffffff; } static void *savestate() { x[-1] = (n<<16)|(i<<8)|j; return x-1; } static void loadstate(uint32_t *state) { x = state+1; n = x[-1]>>16; i = (x[-1]>>8)&0xff; j = x[-1]&0xff; } void srandom(uint32_t seed) { int k; i = n == 31 || n == 7 ? 3 : 1; j = 0; x[0] = seed ? seed : 1; for (k = 1; k < n; k++) x[k] = parkmiller(x[k-1]); for (k = 0; k < 10*n; k++) random(); } char *initstate(unsigned seed, char *state, size_t size) { void *old = savestate(); if (size < 8) return 0; else if (size < 32) n = 0; else if (size < 64) n = 7; else if (size < 128) n = 15; else if (size < 256) n = 31; else n = 63; x = (uint32_t*)state + 1; srandom(seed); return old; } char *setstate(char *state) { void *old = savestate(); loadstate((uint32_t*)state); return old; } long random(void) { long k; if (n == 0) return x[0] = lcg(x[0]); x[i] += x[j]; k = x[i]>>1; if (++i == n) i = 0; if (++j == n) j = 0; return k; } --8vCeF2GUdMpe9ZbK--