diff --git a/relation.admin.inc b/relation.admin.inc
index 820800d..5378719 100644
--- a/relation.admin.inc
+++ b/relation.admin.inc
@@ -232,3 +232,52 @@ function relation_type_delete_confirm_submit($form, &$form_state) {
   $form_state['redirect'] = 'admin/structure/relation';
   return;
 }
+
+/**
+ * Generate relations
+ */
+function relation_generate_form($form, &$form_state) {
+  $types = relation_get_types();
+  foreach( $types as $id => $type) {
+    $types[$id] = $type->name;
+  }
+  $form['relation'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Relation '),
+    '#weight' => 0,
+  );
+  $form['relation']['relation_types'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Relation types'),
+    '#options' => $types,
+  );
+  $form['relation']['relation_number'] = array(
+    '#type' => 'textfield',
+    '#title' => t('How many relations would you like to generate?'),
+    '#default_value' => 10,
+    '#size' => 10,
+  );
+  $form['relation']['relation_kill'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Kill all existing relations'),
+  );
+
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Generate'),
+  );
+  return $form;
+}
+
+function relation_generate_form_submit($form, &$form_state) {
+  $number = $form_state['values']['relation_number'];
+  $types = $form_state['values']['relation_types'];
+  $kill = $form_state['values']['relation_kill'];
+  if (is_numeric($number) && $number>0) {
+    $types = array_keys(array_filter($types));
+    if (count($types)) {
+      $rids = relation_generate_relations($number, $types, $kill);
+      drupal_set_message(t("Generated %count relations", array('%count' => count($rids))));
+    }
+  }
+}
diff --git a/relation.module b/relation.module
index c8e5618..d4b0210 100644
--- a/relation.module
+++ b/relation.module
@@ -138,6 +138,14 @@ function relation_menu() {
     'file' => 'relation.admin.inc',
     'weight' => 10,
   );
+  $items['admin/config/development/generate/relation'] = array(
+    'title' => 'Generate relations',
+    'access arguments' => array('administer relation types'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('relation_generate_form'),
+    'file' => 'relation.admin.inc',
+  );
+
   $items['relation/autocomplete/bundles'] = array(
     'type' => MENU_CALLBACK,
     'access arguments' => array('access content'),
@@ -630,3 +638,63 @@ function relation_views_api() {
     'path' => drupal_get_path('module', 'relation') . '/views',
   );
 }
+
+/**
+ * Generates random relations.
+ */
+function relation_generate_relations($number = 10, $types = array(), $kill = FALSE) {
+  if ($kill) {
+    $query = new EntityFieldQuery();
+    $results = $query->entityCondition('entity_type', 'relation')
+      ->execute();
+    if ($results) {
+      $rids = array_keys($results['relation']);
+      relation_multiple_delete($rids);
+    }
+  }
+  $relation_types = relation_get_types($types);
+  $new_rids = array();
+  foreach ($relation_types as $type => $relation_type) {
+    $available_types = array();
+    foreach ($relation_type->source_bundles as $bundle_key) {
+      list($entity_type, $bundle) = explode(':', $bundle_key, 2);
+      $available_types['source'][$entity_type][] = $bundle;
+    }
+    foreach ($relation_type->target_bundles as $bundle_key) {
+      list($entity_type, $bundle) = explode(':', $bundle_key, 2);
+      $available_types['target'][$entity_type][] = $bundle;
+    }
+    $arity = rand($relation_type->min_arity, $relation_type->min_arity);
+    for ($i = $number; $i > 0; $i--) { // start new relation
+      $entity_keys = array();
+      for ($r_index = 0; $r_index < $arity; $r_index++) {
+        if ($relation_type->directional && $r_index > 0) {
+          $direction = 'target';
+        }
+        else { //use source bundles
+          $direction = 'source';
+        }
+        $entity_type = array_rand($available_types[$direction]);
+        $query = new EntityFieldQuery();
+        $query->entityCondition('entity_type', $entity_type, '=')
+          // Would be nice to ->entityOrderBy('RAND()'); here, and set
+          // range(0, 1). See http://drupal.org/node/1174806
+          ->range(0, 2*$number);
+        if (!in_array('*', $available_types[$direction][$entity_type])) {
+          $query->entityCondition('bundle', $available_types[$direction][$entity_type], 'IN');
+        }
+        $results = $query->execute();
+        $entity_ids = array_keys(reset($results));
+        $key = array_rand($entity_ids); //pseudorandomise until EFQ does random.
+        $entity_keys[] = array(
+          'entity_type' => $entity_type,
+          'entity_id'   => $entity_ids[$key],
+          'r_index'     => $r_index,
+          );
+      }
+      $relation = relation_create($type, $entity_keys);
+      $new_rids[] = relation_save($relation);
+    }
+  }
+  return $new_rids;
+}
