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 BCEB61387FD for ; Sat, 7 Jun 2014 12:13:24 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 875E9E0933; Sat, 7 Jun 2014 12:13:19 +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 469DFE0916 for ; Sat, 7 Jun 2014 12:13:18 +0000 (UTC) Received: from marcec ([77.22.138.176]) by mail.gmx.com (mrgmx003) with ESMTPSA (Nemesis) id 0M2cYX-1WcgRt2zn3-00sNVn for ; Sat, 07 Jun 2014 14:13:16 +0200 Date: Sat, 7 Jun 2014 14:13:11 +0200 From: Marc Joliet To: gentoo-user@lists.gentoo.org Subject: Re: [gentoo-user] OT: Mapping random numbers (PRNG) Message-ID: <20140607141311.0baaa29e@marcec> In-Reply-To: <20140607091911.GA24542@lyseo.edu.ouka.fi> References: <20140606025619.GB3837@solfire> <20140606210329.GA1631@lyseo.edu.ouka.fi> <20140607091911.GA24542@lyseo.edu.ouka.fi> X-Mailer: Claws Mail 3.9.3 (GTK+ 2.24.23; x86_64-pc-linux-gnu) 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: multipart/signed; micalg=pgp-sha1; boundary="Sig_/BcMoZbo+lo9HLrFkjbO23dg"; protocol="application/pgp-signature" X-Provags-ID: V03:K0:JlMiIfmHNH7R6xzTcQcqq9lLRcrJWmc/bK3QMz5uhZOgqbWmnxf Zr9R1MFl4dpyoTqOv34Um58gwmni6SKc/FsSnN7YhuS1/kwZTOjeHdDXZ4WaalBRXHLTnUD LOjiywhv68fntztqrGGWOLWXE9VpX6IUIEidcu80I9ZrMQQX+MCR3N7MONkFR3nHn4xkOY7 InuPTcvztiytxJVYuP/2Q== X-Archives-Salt: c0d68311-88f3-45ab-8fd6-8f3150e11da9 X-Archives-Hash: e076030ed64ef464b3c1e21a49d73ed9 --Sig_/BcMoZbo+lo9HLrFkjbO23dg Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Am Sat, 7 Jun 2014 12:19:11 +0300 schrieb Matti Nykyri : > On Sat, Jun 07, 2014 at 12:03:29AM +0300, Matti Nykyri wrote: [...] > unsigned char get_6bits ()=20 > { > static unsigned int rand =3D 0; //(sizeof(int) =3D 32) Just an itty bitty nitpick: since you already require C99 as per the for lo= op below, you might as well use uint32_t (from stdint.h) instead of assuming t= hat sizeof(int) =3D=3D 32 :) . > static char bits_avail =3D 0; > unsigned char result =3D 0; >=20 > //get 2 bits 3 times: 32 is devidable by 2 > for (int i =3D 0; i < 3; i++) { // --std=3Dc99 > //Fill buffer if it is empty! > if (!bits_avail ||=C2=A0bits_avail < 0 ) { //if bits_avail < 0 it is an= error! > // Use the correct call for ISAAC instead of rand() > rand =3D rand(); > =09 > bits_avail =3D 32; > } >=20 > result <<=3D 2; //move two bits to left. > result =3D result | (rand & 0x3); //add two least signifigant bits to t= he result. > rand >>=3D 2; //move two bits to right. > bits_avail -=3D 2; > } >=20 > return result; //result has 6 bits of random data... > } >=20 > char next_character() > { > unsigned char idx =3D 0; > do { > idx =3D get_6bits(); > } while (idx > 61); >=20 > return S[idx]; > } >=20 > Very simple :) [...] --=20 Marc Joliet -- "People who think they know everything really annoy those of us who know we don't" - Bjarne Stroustrup --Sig_/BcMoZbo+lo9HLrFkjbO23dg Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAEBAgAGBQJTkwHbAAoJEL/Q5oYsiHj079cP/0l6IpcnRU5U9sWhTwfD/DNp tpZZCZzwZHd+iXXGuUj5qjAAY3UfObl3kleb8ephblmPrwKfTBy8zUCaqduwODrk Msx6q7aRTEGM7VTVjQWYOEOT9/I+Q1S31YCZ5Vda3EvGzaJ5Hyk6/uMSNJWBjq65 ZJMtAQDQjMq8tWc+SjEbXp8fy5RhTaZqMrvxQ6Bnfgy3ql6M0aULgCvJSDYzENTo m9r0IJJ36syfmJEozY35oNAsNAglJ4559JLDQ8wZNw76UkHfoTmWQjvwjE9tEYJL Tncz9fniiWtzVM+6dQlYjElKuPuyjausdGP6X7NOoLjHmauN4t5fAFcmYC7lrWR1 k5RaFHObtGQEU89bsgj/uP7iZmsnVPc3ZbKZM2zhp7fJuX2S9/JZ/NHMoRwtX5gZ dI8mPS69qC5w3g8BU+JOLBgCGYrxS9ijOIKvlFIC+iFJnWW6o7+qV4KILaM9Gk+M 646IDasZxdsb2GUcUntrz+YDKGV6EQQxahpWIFoh2yVk1CQLaW/AQQxd+dELk3RF t/dKrj3Vz8F27vSWIhIDNqUcz9v+HEUzHuZrse+i/FG5ILcHiv9gGAv35hqQw3bi ZaXSVZROnwdI/EasWgdrbNVRs8MCd7L9vR3vpzD5dy6CeLrQaggBdMIcna+IAUdo QkOUsQu6Zw6DHf0SU07f =Kh0o -----END PGP SIGNATURE----- --Sig_/BcMoZbo+lo9HLrFkjbO23dg--