{"title":"System.Random(Integer) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/system/system-random-method/","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/methods-auto/system/system-random-method, 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/methods-auto/system/system-random-method","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":"Returns a pseudo-random number.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"System.Random(Integer) Method","slug":"systemrandominteger-method","at":0,"chars":1580},{"level":2,"title":"Syntax","slug":"syntax","at":124,"chars":141},{"level":2,"title":"Parameters","slug":"parameters","at":265,"chars":199},{"level":2,"title":"Return Value","slug":"return-value","at":464,"chars":58},{"level":2,"title":"Remarks","slug":"remarks","at":522,"chars":229},{"level":2,"title":"Example","slug":"example","at":751,"chars":695},{"level":2,"title":"Related information","slug":"related-information","at":1446,"chars":134}],"text":"# System.Random(Integer) Method\n> Version: _Available or changed with runtime version 1.0._\nReturns a pseudo-random number.\n## Syntax\n```al\nNumber :=   System.Random(MaxNumber: Integer)\n```\n> NOTE\n> This method can be invoked without specifying the data type name.\n## Parameters\nMaxNumber\nType: ../integer/integer-data-type\nThe largest acceptable number. In effect, you are setting a range from one (1) to the number that you specify with the MaxNumber parameter.\n## Return Value\nNumber\nType: ../integer/integer-data-type\n## Remarks\nIf MaxNumber is negative it acts as a positive.\nIf MaxNumber is zero, this method always returns 1.\nA number is always chosen from the same set of numbers. Use system-randomize-method to generate a new set of numbers.\n## Example\nThis example shows how to generate a pseudo-random number. The value of the variable Number2 is positive though the value of MaxNumber is negative and the value of the variable Number3 is always 1 because MaxNumber is 0.\n```al\nvar\n    x: Integer;\n    y: Integer;\n    z: Integer;\n    Number1: Integer;\n    Number2: Integer;\n    Number3: Integer;\n    Text000: Label 'Number1 = %1, Number2 = %2, Number3 = %3';\nbegin\n    x := 100; // x is assigned a positive value.\n    y := -100; // y is assigned a negative value.\n    z := 0; // z is assigned zero.\n    Number1 := Random(x);\n    Number2 := Random(y);\n    Number3 := Random(z);\n    Message(Text000, Number1, Number2, Number3);\nend;\n```\n## Related information\nsystem-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}