RandInt and GenerateRandomCode20 always gives the same value?

Hello again,

I am currently writing codeunits for Automated Testing in BC. I tried the GenerateRandomCode20 and RandInt from the Codeunit “Library - Utility” and Codeunit “Library - Random”.But when i use them in different function the alwas create the same code what leads to the following error:

The record in table XYZ already exists. Identification fields and values: Packaging Code=‘GU000000060000000000’,Line No.=‘0’

Some ideas how to avoid this behaviour?

Thank you in advance.


I have never had any issues like that, it always worked fine for me. Which version of BC are you using?

Hey Erik, i am using BC 15.

Here an example:

I am calling this function from my own library codeunit various times in one of my test codeunits

procedure CreatePackaging(var Packaging: Record “XYZ Packaging”)
Packaging.“Code” := LibraryUtility.GenerateRandomCode20(Packaging.FIELDNO(“Code”), DATABASE::“XYZ Packaging”);
Packaging.Validate(“Packaging Type Code”, CreatePackagingTypeCode());

I think i might use


in the test codeunit.

or a TestRunner with

TestIsolation = Function;

as workaround.