From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 020971387FD for ; Fri, 6 Jun 2014 18:39:37 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0B08BE0A98; Fri, 6 Jun 2014 18:39:33 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id C5BA6E0A80 for ; Fri, 6 Jun 2014 18:39:31 +0000 (UTC) Received: from gmx.net ([84.133.162.149]) by mail.gmx.com (mrgmx002) with ESMTPSA (Nemesis) id 0LzKyn-1WgJkG1M6j-014WFS for ; Fri, 06 Jun 2014 20:39:30 +0200 Received: by gmx.net (nbSMTP-1.00) for uid 1001 (using TLSv1/SSLv3 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) meino.cramer@gmx.de; Fri, 6 Jun 2014 20:39:29 +0200 (CEST) Date: Fri, 6 Jun 2014 20:39:28 +0200 From: meino.cramer@gmx.de To: gentoo-user@lists.gentoo.org Subject: Re: [gentoo-user] OT: Mapping random numbers (PRNG) Message-ID: <20140606183928.GC4718@solfire> References: <20140606025619.GB3837@solfire> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@lists.gentoo.org Reply-to: gentoo-user@lists.gentoo.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: User-Agent: mutt-ng/devel-r804 (Linux) X-Provags-ID: V03:K0:FiSieUiQ9ERfo5bJ9cWwOrcCCh8JadlfzhJmvXjFejQJ+nii4Ya HsUheK1Bo7M0QiGQq0xvG7ZlRhj/FxIzakwSrG2C4u4efPTNyGzfik3uX8ji0zQymzkZTgp eHgwfbYUuq0uFzA8Qbh4m3BZ/VgtKhO4Jd2/5Aq1l027uKhEFm5UU95fTC6XR7QYV3skjr9 ZPL/eP9wwOogJl3USUv/A== X-Archives-Salt: 4a319ff2-d50a-4acf-9b9d-a38c70c3f0d1 X-Archives-Hash: d61e74a407baadb0c4f74ca318bb4ce8 Canek Pel=E1ez Vald=E9s [14-06-06 17:36]: > On Thu, Jun 5, 2014 at 9:56 PM, wrote: > > Hi, > > > > I am experimenting with the C code of the ISAAC pseudo random number ge= nerator > > (http://burtleburtle.net/bob/rand/isaacafa.html). > > > > Currently the implementation creates (on my embedded linux) 32 bit > > hexadecimal output. >=20 > So it's a 32 bit integer. >=20 > > From this I want to create random numbers in the range of [a-Za-z0-9] > > *without violating randomness* and (if possible) without throwing > > away bits of the output. >=20 > You mean *characters* int the range [A-Za-z0-9]? >=20 > > How can I do this mathemtically (in concern of the quality of output) > > correct? >=20 > The easiest thing to do would be: >=20 > -------------------------------------------------------------------------= ------ > #include > #include > #include >=20 > #define N (26+26+10) >=20 > static char S[] =3D { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', > 'K', 'L', 'M', > 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', > 'X', 'Y', 'Z', > 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', > 'k', 'l', 'm', > 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', > 'x', 'y', 'z', > '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; >=20 > int > next_character() > { > // Use the correct call for ISAAC instead of rand() > unsigned int idx =3D rand() % N; > return S[idx]; > } >=20 > int > main(int argc, char* argv[]) > { > // Use the correct call for initializing the ISAAC seed > srand((unsigned int)time(NULL)); > for (int i =3D 0; i < 20; i++) // --std=3Dc99 > printf("%c\n", next_character()); > return 0; > } > -------------------------------------------------------------------------= ------ >=20 > If the ISAAC RNG has a good distribution, then the next_character() > function will give a good distribution among the set [A-Za-z0-9]. >=20 > Unless I missunderstood what you meant with "create random numbers in > the range of [a-Za-z0-9]". >=20 > Regards. > --=20 > Canek Pel=E1ez Vald=E9s > Profesor de asignatura, Facultad de Ciencias > Universidad Nacional Aut=F3noma de M=E9xico >=20 Hi, Thank you very much for the input! :) I have a question about the algorithm: Suppose rand() has an equal distribution of numbers and furthermore one has a count of 2^32 random numbers listed in numerical sort order. In this list each number would appear (nearly) with the same count: 1 To get an better imagination of that...suppose the rand() would only=20 return numbers in the range of 1...12 and the alphabet has only 8 characters (as 2^32 is not devideable by 62) rand(): 1 2 3 4 5 6 7 8 9 10 11 12 rand()%N : rand()%7 1 2 3 4 5 6 7 0 1 2 3 4 =20 or in other words: An even distribution of numbers of rand()=20 would result in a unevenly distributed sequence of characters...or? This would break the quality of ISAACs output. I am sure I did something wrong here...but where is the logic trap? Thank you very much for any help in advance! Best regards, mcc