Discussion:
Array of random integers
(too old to reply)
Bart
2017-04-16 11:21:47 UTC
Permalink
Raw Message
Hi,

Would a function that returns an array of unique (=non-repeating)
random integers in a certain range be accepted as a contribution to
e.g. the math unit?

I had the following function prototypes in mind:

{
Returns an array of aSize random integers without duplicates ranging from
aFrom (inclusive) to aTo (exclusive).
- aFrom and aTo must be positive integers
- aTo must be > aFrom
- aSize must be <= aTo - aFrom
- if either of these conditions is not met, an empty array will be returned.
}
function RandomArray(aFrom, aTo, aSize: Integer): TIntegerDynArray; overload;
function RandomArray(aFrom, aTo: Integer): TIntegerDynArray; overload;
function RandomArray(Range: Integer): TIntegerDynArray; overload;

function RandomArray(aFrom, aTo, aSize: Int64): TInt64DynArray; overload;
function RandomArray(aFrom, aTo: Int64): TInt64DynArray; overload;
function RandomArray(Range: Int64): TInt64DynArray; overload;

( TInt64DynArray = array of Int64)

My current implementation builds such an array of size 1 million
32-bit integers in 59 msec (on a 7 year old laptop with an i5 CPU M
430 @ 2.27 GHz with 4 GB Ram).

Bart
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.fre

Loading...