More Test Data Generation Tips

by Andy Masters 14. June 2010 20:28

Selecting random rows from existing databases:

NewID() generates a GUID which can then be used to sort the rows into a random order

SELECT
 TOP n
 <query>
 ORDER BY NEWID()

You can use this technique to generate whatever you like names, addresses or ref codes. If you do it once per column, you have pseudo random dta i.e. you won't be using a whole specific row from the database.


Excel: To generate test data in excel with a particular frequency distribution:

Say you want to generate random ISO 4217 'currency codes' but 80% of the time you want GBP, 10% USD and 10% JPY.

Create a range of data on a separate tab (call it DataDistribution) as follows
A1:A10 number 1-10
B2:B8 'GBP'
B9 'USD'
B10 'JPY'

Then to generate a random value according to the required frequency distribution, you can use the following function:

=VLOOKUP(RANDBETWEEN(1,10),DataDistribution!A1:A10,1,FALSE)

You can amend the size of the vlookup array to meet the needs of your frequency distribution - have 100 rows if you want percentages.

Warning - be careful using spreadsheets with formulas that use random data for input data. Excel will recalculate the formulas when the file is opened or when you edit the spreadsheet. To overcome this, copy and paste your data using the 'paste special\values' option.

Tags: , , ,

Testing

Comments

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen