forked from ifsmirnov/jngen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## Math-ish primitives | ||
|
||
Jngen provides several free functions and a generator class *MathRandom* to help generating numbers and combinatorial primitives. All interaction with *MathRandom* goes via its global instance called *rndm*. The source of randomness is *rnd*. | ||
|
||
### Standalone functions | ||
|
||
#### bool isPrime(long long n) | ||
* Returns: true if *n* is prime, false otherwise. | ||
* Supported for all *n* from 1 to 3.8e18. | ||
* Implemented with deterministic variation of the Miller-Rabin primality test so should work relatively fast (exact benchmark here). | ||
|
||
### MathRandom methods | ||
|
||
#### long long randomPrime(long long n) | ||
#### long long randomPrime(long long l, long long r) | ||
* Returns: random prime in range *[2, n)* or *[l, r]* respectively. | ||
* Throws if no prime is found on the interval. | ||
|
||
#### Array partition(int n, int numParts) | ||
#### Array partitionNonEmpty(int n, int numParts) | ||
#### Array64 partition(long long n, int numParts) | ||
#### Array64 partitionNonEmpty(long long n, int numParts) | ||
* Returns: a random ordered partition of *n* into *numParts* parts. In case of *partitionNonEmpty* each element of the result is positive. | ||
|
||
#### template<typename T> <br> TArray<TArray<T>> partition(TArray<T> elements, int numParts) | ||
#### template<typename T> <br> TArray<TArray<T>> partitionNonEmpty(TArray<T> elements, int numParts) | ||
* Returns: a random partition of the array *elements* into *numParts* parts. | ||
|
||
#### template<typename T> <br> TArray<TArray<T>> partitionNonEmpty(TArray<T> elements, const Array& sizes) | ||
* Returns: a random partition of the array *elements* into parts, where the size of each part is specified. | ||
* Note: sum(*sizes*) must be equal to *elements.size()*. |