Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7186547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:39:13+00:00 2026-05-28T18:39:13+00:00

I created a random generator for cryptography purposes I would like to know if

  • 0

I created a random generator for cryptography purposes I would like to know if it is secure enough. If it is you’re free to use it of course. Thanks in advance for reading my wall of text 😀

Explanation of functions

The $this->pref_hash_algo($bits_of_entropy=null, $inclusive=false) function gets the default hashing method (in my case sha256) or if $bits_of_entropy is given it gets the optimal hashing algorithm that is either inclusive or not. For instance 230 bits of entropy inclusive would return sha256 while exclusive would give sha224.

The algorithm returned from self::$HASH_PREFERENCES['128'][0] is ripemd128

For $this->hash($input, $algorithm=null, $output_type=self::OUTPUT_HEX) it only does a PHP hash($input, $algorithm[, $binary]) with extra checking if the algorithm is considered secure and support for more output types then binary and hexadecimal.

Generation code

For easy access moved first version to http://pastebin.com/YtJFvpah

Update

Based on your input I have altered the code to the following: http://pastebin.com/bQ5tFDdh

Summary of edits:

  • Not hashing, but only formatting /dev/urandom output.
  • Added meantime output hashing, for when hashing algorithm has too little output for the requested amount of random bits (for example sha512 when 4000 bits are requested)

Testing

Case 1

I ran php /my/path/to/file.php | ent to test the /dev/urandom method and the alternative method on a 2.000.000 byte sample.

  • /dev/urandom gave 7.999903 bits per byte entropy. ( http://pastebin.com/NLqZ5Kza )
  • Alternative method gave 7.99913 bits per byte entropy. ( http://pastebin.com/rnebrvKg )

Case 2

I created a 4,7MB binary file using the ALTERNATIVE METHOD (when /dev/urandom is disabled/not available) and ran dieharder -a -f /home/beanow/random.input -t 10:

  • /dev/urandom gave: 2 weaks ( http://pastebin.com/HiwQeJtP )
  • Alternative method gave: 0 weaks ( http://pastebin.com/x1VbEhzg )

Case 3

The same as case 2 but with 20MB binary files and removing the -t argument to use the default setting.

  • /dev/urandom gave: 4 weaks ( http://pastebin.com/hwqQBTqu )
  • Alternative method gave: 1 weak ( http://pastebin.com/cvPXiGBV )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:39:15+00:00Added an answer on May 28, 2026 at 6:39 pm

    There are a number of tests you can run against your output to determine how random it really is.

    ent – A Pseudorandom Number Sequence Test Program

    … [ent] applies various tests to sequences of bytes stored in files and reports the results of those tests. [ent] is useful for evaluating pseudorandom number generators for encryption and statistical sampling applications, compression algorithms, and other applications where the information density of a file is of interest.

    The diehard test suite

    … a battery of statistical tests for measuring the quality of a random number generator. Wikipedia

    The dieharder test suite

    The primary point of dieharder (like diehard before it) is to make it easy to time and test (pseudo)random number generators, both software and hardware, for a variety of purposes in research and cryptography.

    Passing both the diehard and dieharder test suites is quite difficult with a home-grown pseudo-random number generator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a color generator based on random numbers, which might
I have created a random string generator. What happens is that the user would
I am looking for a pseudo random number generator which would be specialized to
I want to use a random number generator that creates random numbers in a
I'd like to create a random string, consisting of alpha-numeric characters. I want to
I already wrote a random generator which take arguments a and b, where a
I know there have been several posts about random word generation based on large
See this related question on more generic use of the Boost Random library. My
I'm using Microsoft SQL Server 2005. I'm creating a random record generator that will
Suppose you have a random number generator that generates a random floating point number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.