Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2017-04

Array of random integers

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bart

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

Reply by email