BigInt random numbers

Up a level : Algebra and Arithmetic
Previous page : RSA cryptosystem

In this page you can generate BigInt random numbers in between two given values, a, b including the given values, and check if large numbers are prime.

  • Generator 1  Generates a random big number between two numbers.
  • Generator 2 Generates a random number with a selected number of decimal digits or bits. Can also be used to check if a number is a prime number.

Generator 1

It first calculates the difference c=b-a, then it splits the value c in groups of 10 digits, starting from the most significant figure. It will then loop through c in the following way:

  1. Let the result be “”.
  2. Get the most significant part not yet handled, say f.
  3. Generate a random integer between 0 and f, inclusive, say r.
  4.  If r=f, then set f to the next 10 digit part of c, else set f=10000000000. If so, use that f for all following part, except possibly the last where f=10^number of digits left.
  5. Concatenate r to the result.
  6. Repat from 3  until all parts of c is handled.
  7. Finally, add back a.

This is the code. It is a metod inside an object.

Generator 2

This is using the same method to generate a number as generator 1. It then checks if it is a prime number, if not it steps to the next likely prime number, and so on.  For small numbers it does an exact test, for larger it uses 33 iterations of the Miller–Rabin test . That means that the risk for a false positive is in the order of 1/433, or 1.355·10-20 . In other worlds, virtually in existent.

You can store the generated random primes to use in the RSA-algorithm.

Up a level : Algebra and Arithmetic
Previous page : RSA cryptosystemLast modified: Oct 29, 2023 @ 19:09