All of lore.kernel.org
 help / color / mirror / Atom feed
From: wudmx@web.de (Andreas Leppert)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Creating the same random numbers
Date: Sun, 30 Jan 2011 00:49:10 +0100	[thread overview]
Message-ID: <20110129234909.GD3225@yoda> (raw)
In-Reply-To: <1041152607-1296331182-cardhu_decombobulator_blackberry.rim.net-897203629-@b27.c7.bise7.blackberry>

On Sat, Jan 29, 2011 at 07:59:34PM +0000, creslin at gmail.com wrote:
> But in short answer yes, if you use the same seed the same answer
> would be generated, assuming no further entropy is used later I.e
> dependent on method employed to expand. Though then the 'randomness'
> is in the seed not the output. Its this capability which allows simple
> access control token devices to operate.
> 
I'm not quite familiar with the number generators in the kernel. Right
now I do this to get a random number betwen min and max:

/* compute the random value within the given min and max wrt to step */
int tmp_bytes, range;

range = max - min + 1;
get_random_bytes(&tmp_bytes, sizeof(tmp_bytes));
if (0 > tmp_bytes)
	tmp_bytes = -tmp_bytes;
new_random_param->curval = tmp_bytes % range + min;

You mentioned the seed value. Is there a way to set a seed value before
I invoke get_random_bytes? Could you direct me to a page / source file
where I can get more information about it?

Thanks for all responses so long!
Andreas Leppert

  parent reply	other threads:[~2011-01-29 23:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-29 14:09 Creating the same random numbers Andreas Leppert
2011-01-29 19:34 ` Anuz Pratap Singh Tomar
2011-01-29 21:09   ` Enrico Granata
2011-01-29 23:38   ` Andreas Leppert
     [not found]   ` <1041152607-1296331182-cardhu_decombobulator_blackberry.rim.net-897203629-@b27.c7.bise7.blackberry>
2011-01-29 23:41     ` Andreas Leppert
2011-01-30  0:11       ` Manohar Vanga
2011-01-29 23:49     ` Andreas Leppert [this message]
2011-01-30  0:34       ` Javier Martinez Canillas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110129234909.GD3225@yoda \
    --to=wudmx@web.de \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.