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.

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.


 

Up a level : Algebra and Arithmetic
Previous page : RSA cryptosystemLast modified: Jul 3, 2022 @ 19:55