Log In    |    Knowledge Base    |    4D Home
Tech Tip: Generating random test data
Published On: June 23, 2000
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Here is a project method that can be used to fill a test table with random string data. In this example, the database contains a table [SourceStrings] with a single string field "FiftySixChars". Every time the method below is executed, $numCreated random text strings will be created. The random characters are selected from ASCII codes 33 (exclamation point) to 126 (tilde) and include upper and lower case characters and punctuation, but no white space. The resulting random strings are not very legible but can be useful for stress-testing or performance benchmarks where a large number of records are needed.

Cut and Paste the following code example into your
own 4D project

CONFIRM("Add "+String($numCreated)+" random strings to [SourceStrings]?")
If (OK=1)
 For ($i;1;$numCreated)
  CREATE RECORD([SourceStrings])
  For ($x;1;$stringLength)
  End for
  SAVE RECORD([SourceStrings])
 End for
 $message:="Created "+String($numCreated)+" random strings of length "
 $message:=$message+String($stringLength)+" in [SourceStrings]."
End if