{"title":"Random test data","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-random-test-data/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-random-test-data, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-random-test-data","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Learn how to generate random data for application tests in Business Central, and how to seed random values so you can reproduce and fix test failures.","date":"2026-08-24","meta":{"topic":"concept-article"},"outline":[{"level":2,"title":"Using random data","slug":"using-random-data","at":205,"chars":2446},{"level":3,"title":"Seeding test data","slug":"seeding-test-data","at":1258,"chars":1393},{"level":2,"title":"Related information","slug":"related-information","at":2651,"chars":49}],"text":"You can use codeunit Library - Random to help generate random data for your application tests. Only use hardcoded values in tests when you really need them. For all other data, consider using random data.\n## Using random data\nWhen your application test doesn't require a specific value, use the methods in the Library - Random codeunit to generate random data for you on the fly. For example, the following code snippet illustrates how you generate two values and test that the second is larger than the first.\n```al\nvar\n    LibraryRandom: Codeunit \"Library - Random\";\n    Assert: Codeunit Assert;\n    Number1: Integer;\n    Number2: Integer;\nbegin\n    Number1 := LibraryRandom.RandInt(10);\n    Number2 := Number1 + LibraryRandom.RandInt(10);\n\n    Assert.IsTrue(Number2 > Number1, Err);\nend;\n```\nThis example uses random integers because it doesn't matter if the second number is 2 or 2000. You can use similar code to generate random decimal numbers, dates, and so on.\n> TIP\n> Use the Any library<https://github.com/microsoft/BCApps/tree/main/src/Tools/Test%20Framework/Test%20Libraries/Any> in the BCApps repository to generate pseudo-random values during test set-up. This module generates the same set of numbers, allowing you to reproduce test failures.\n### Seeding test data\nSometimes random values lead to test failures, so you want to be able to reproduce the failure and fix it. In most codeunits in the application test libraries, you find an Initialize method that often contains the following statement:\n```al\nLibraryRandom.SetSeed(1);\n```\nThe SetSeed method on the Library - Random codeunit injects a starting point for the random numbers that the test generates. Then, when you rerun the test or try to reproduce the failure in another table or database, the same sequence of records is created each time. The following code snippet illustrates this seeding of data.\n```al\nRandomHistory.DeleteAll();\n\nLibraryRandom.SetSeed(1);\n\nfor Counter := 1 to 400 do begin\n    RandomHistory.EntryNo := Counter;\n    RandomHistory.RandomValue := LibraryRandom.RandDec(1000, 2);\n    RandomHistory.Insert();\nend;\n```\nIf a test codeunit contains two tests, and both use random data, they run in sequence so that Test A gets Random Data A and Test B gets Random Data B. But if you decide to run only Test B, it gets a new random value. Similarly, if you change the order of the tests in your test codeunit, they all get new random data. You can use this behavior in different ways. For example, you can call the SetSeed method in the beginning of each test to ensure that the same set of random numbers is generated, or you can use this for fuzzy testing.\n## Related information\ndevenv-testing-application"}