14. Finding a random divisor {VeryLargeIntegers} | R Documentation |
divisor
returns a randomly chosen divisor of a given number.
divisor(n, iter = 100) ## Default S3 method: divisor(n, iter = 100) ## S3 method for class 'numeric' divisor(n, iter = 100) ## S3 method for class 'vli' divisor(n, iter = 100)
n |
object of class vli or 32 bits integer |
iter |
number of iterations for testing if the given number is prime; numeric |
The algorithm determines if the given number is prime or composite by usign the Miller-Rabin Probabilistic Primality Test. If it is prime, it returns the number itself. If it is composite, it returns a randomly chosen divisor. The number of iterations is configurable to set the desired accuracy. A too low number of iterations could cause an infinite loop because of being looking for a divisor of a prime number.
object of class vli
Javier Leiva Cuadrado
r <- rvliprime(100) r x <- r * 51 x divisor(x, iter = 100)