Entry:
Random Division of a Population Into Two Groups
An idea I head while at the YMCA, listening to a lecture on the statistics of psychology:
<?php
$this->db->order_by(rand());
$query = $this->db->get('table');
foreach $query as $row
$count_total = $this->db->count('table');
$this->db->where($group, 'group_1');
$count_1 = $this->db->count('table');
if ( $count_1 < ( $count_total / 2 ) )
{
$insert_data['group'] = 'group_1';
$this->db->where($id, $this->row->id);
$this->db->insert($insert_data, 'table');
}
else
{
$insert_data['group'] = 'group_2';
$this->db->where($id, $this->row->id);
$this->db->insert($input_data, 'table');
}
endforeach
?>
Three possible problems:
- Doing only one pass like this will not necessarily be enough.
- What about populations with a count() that's not even? Or that is even?
- I'm not sure about my
order_by( rand() )andinsert( $input_data, 'table' )lines.
