Skip to content

Instantly share code, notes, and snippets.

@mwacc
Created July 23, 2013 12:56
Show Gist options
  • Save mwacc/6062165 to your computer and use it in GitHub Desktop.
Save mwacc/6062165 to your computer and use it in GitHub Desktop.
Product list generator for BasketAnalys example
class Constants {
static final goods = [
'Apple', 'Orange', 'Pineaple', 'Cherry', 'Beef', 'Sugar', 'Milk',
'Pear', 'Limon', 'Blubbery', 'IceCream', 'Cake', 'Orange', 'Milk',
'Cola', 'Bread', 'Coffe', 'Cookies', 'Beer', 'Tea', 'Salmon', 'Steal Water', 'Nuts']
}
rand = new Random()
def createProduct() {
return Constants.goods[ rand.nextInt( Constants.goods.size() ) ]
}
def createTransaction(int itemsNum) {
List<String> list = new ArrayList<String>();
for(int i = 0; i < itemsNum; i++) {
String newProduct = createProduct();
if(list.contains(newProduct)) {
i--;
}else{
list.add(newProduct);
}
}
// create relation betweens Steal Water and Nuts
if(list.contains('Nuts') && !list.contains('Steal Water') && (rand.nextInt(10)+1) % 7 != 0) {
list.add('Steal Water')
}
return list.join(',')
}
def createDataSet(int recordsNum) {
for(int i = 0; i < recordsNum; i++){
System.out.println( createTransaction(rand.nextInt(5)+4) )
}
}
createDataSet(250)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment