Free Random Numbers

Today's Messages (off)  | Unanswered Messages (on)

Forum: Math and Practical
 Topic: Converting random bytes into a range
Converting random bytes into a range [message #65] Wed, 06 April 2011 00:48
TRNG98 is currently online  TRNG98
Messages: 20
Registered: January 2011
Location: Lund
Senior Member
Now, if you wish to convert a random byte (0..255) into a digit (0..9) you can do like this:

  1. You combine the digits into the maximum that your input can generate (99)
  2. You discard the rest of the range (100..255)

You can discard less if you have 10 bit input and can generate 3 digits (0..999 and discard only 1000..1023).

This is how to solve for a optimum solution:

  1. Your input is (0..255) so, in bits it is log (256)/log(2) = 8 (any log will do)
  2. Your range is log (10)/log(2) = 3.32
  3. The ratio of a digit to a byte is: 3.32/8=0.415

By adding (to itself) the number 0.415 we see how much we can use of the input, and how large the loss is:

Digits   Fill    Number of bytes 
 1      0.415     1
 2      0.830     1
 3      1.246     2
 4      1.661     2
 5      2.076     3
 6      2.491     3
 7      2.907     3
 8      3.322     4
 9      3.373     4
10      4.152     5
11      4.568     5
12      4.983     5

Since the input comes in bytes, using 3 bytes and convert into 7 digits produce a loss of (3.000-2.907)/7=0.013 bytes for each output digit. This obviously get better if we use larger numbers. If you use 5 bytes and generate 12 digits, the loss is only 0.0014 bytes/digit.
A compromise is usually easy to find.

TRNG98 We sell hardware random number generators
 Topic: User Accounts
User Accounts [message #121] Sat, 19 January 2013 08:54
admin is currently online  admin
Messages: 9
Registered: November 2010
Location: Lund
We now restrict the members listing to users with at least one forum post. This is in response to many spam-bots, who register dummy accounts on the server. We plan to regularly remove these accounts after 12 months. Please consider contacting us if you merely use your account for reading on the forum.
 Topic: Welcome to the randomserver forum
icon12.gif  Welcome to the randomserver forum [message #18] Tue, 23 November 2010 13:18
admin is currently online  admin
Messages: 9
Registered: November 2010
Location: Lund
Welcome We set up this forum for David.

We wish you all welcome to the new forum! Flower

Exclamation You are required to answer/update your account profile and submit info about your country. If you enter incorrect information or leave mandatory fields blank, your account may be removed.

[Updated on: Wed, 16 February 2011 01:46]

Report message to a moderator

Current Time: Sun Apr 30 03:26:50 W. Europe Daylight Time 2017