automate tuple creation
H. S. Teoh
hsteoh at quickfur.ath.cx
Thu Jan 20 00:30:44 UTC 2022
On Thu, Jan 20, 2022 at 12:12:56AM +0000, forkit via Digitalmars-d-learn wrote:
[...]
> createBoolAssociativeMatrix(mArrBool,3, 2);
>
> [ [1000:[1, 0]], [1001:[1, 1]], [1001:[1, 0]]]
>
>
> where 1000 is some random id...
Do the id's have to be unique? If not, std.random.uniform() would do
the job.
If they have to be unique, you can either use a sequential global
counter (a 64-bit counter will suffice -- you'll won't exhaust it for at
least 60+ years of bumping the counter once per CPU tick at 8.4 GHz), or
use an AA of ids already generated and just call uniform() to generate a
new one until it doesn't collide anymore.
T
--
A mathematician learns more and more about less and less, until he knows everything about nothing; whereas a philospher learns less and less about more and more, until he knows nothing about everything.
More information about the Digitalmars-d-learn
mailing list