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 8AD8A1381FA for ; Fri, 6 Jun 2014 03:59:18 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A7328E0A89; Fri, 6 Jun 2014 03:59:13 +0000 (UTC) Received: from mail-ig0-f174.google.com (mail-ig0-f174.google.com [209.85.213.174]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 1A09EE0887 for ; Fri, 6 Jun 2014 03:59:11 +0000 (UTC) Received: by mail-ig0-f174.google.com with SMTP id h3so224787igd.7 for ; Thu, 05 Jun 2014 20:59:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=kYciShY6fwwKj0CwbPBVdPq5Jbf95S38TzdjiDfzX20=; b=GdwZ9/NH64zQ2RDtKTc73Lt+99d9Tq9ncqVrEJNvHaIvqWq9jjwFeaK8Zkc8d5BCN0 igBAGUG+uXWepO9WqNwJ5zFuktUMoPlME4uAYS94YDWkWw1wmbpo+DjD/G4yLBb7Fy4R oLY0ArOaIYf+m4YXP4l3OEoHde3EqdZ/NddgPln8455ZBTgM3rIAcmdUi8EnI9wJy4d0 v7Dk/W3sRXbq1eldOJ9lCAQmGLH/rXRsEsJlRJExrjhKe+ZlproIGhW5BYqXpqWtTlQX BeUR7t2HZVU9kCw6tWtgy1+P8wzPUmPYC0tpFo/WZvGVG7d4MHX5RSd0g0rAN/mqBKoI zVsQ== X-Received: by 10.42.64.7 with SMTP id e7mr2216817ici.90.1402027151257; Thu, 05 Jun 2014 20:59:11 -0700 (PDT) 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 Received: by 10.64.136.226 with HTTP; Thu, 5 Jun 2014 20:58:51 -0700 (PDT) In-Reply-To: <20140606025619.GB3837@solfire> References: <20140606025619.GB3837@solfire> From: =?UTF-8?B?Q2FuZWsgUGVsw6FleiBWYWxkw6lz?= Date: Thu, 5 Jun 2014 22:58:51 -0500 Message-ID: Subject: Re: [gentoo-user] OT: Mapping random numbers (PRNG) To: gentoo-user@lists.gentoo.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 13a49c68-f642-4892-882d-e7434b3a3dda X-Archives-Hash: ccc5fe6b55bead49d0c70e0b51c0080e On Thu, Jun 5, 2014 at 9:56 PM, wrote: > Hi, > > I am experimenting with the C code of the ISAAC pseudo random number gene= rator > (http://burtleburtle.net/bob/rand/isaacafa.html). > > Currently the implementation creates (on my embedded linux) 32 bit > hexadecimal output. So it's a 32 bit integer. > 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. You mean *characters* int the range [A-Za-z0-9]? > How can I do this mathemtically (in concern of the quality of output) > correct? The easiest thing to do would be: ---------------------------------------------------------------------------= ---- #include #include #include #define N (26+26+10) 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' }; int next_character() { // Use the correct call for ISAAC instead of rand() unsigned int idx =3D rand() % N; return S[idx]; } 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; } ---------------------------------------------------------------------------= ---- 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]. Unless I missunderstood what you meant with "create random numbers in the range of [a-Za-z0-9]". Regards. --=20 Canek Pel=C3=A1ez Vald=C3=A9s Profesor de asignatura, Facultad de Ciencias Universidad Nacional Aut=C3=B3noma de M=C3=A9xico