$event->eid)); $attendees = $attendee_query->fetchAll(); //assuming there's less than 900 people, generate numbers within that range and shuffle the order $numbers = range(100,750); shuffle($numbers); foreach ($attendees as $attendee) { $luckynum = $numbers[$i++]; drupal_set_message(t('Updating user !id to have lucky number !num.', array('!id' => $attendee->nid, '!num' => $luckynum))); //run an update query db_update('booking_person') ->fields(array ( 'booking_luckynum' => $luckynum, )) ->condition('nid', $attendee->nid) ->execute(); } drupal_set_message(t('Finished.')); return t("