• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Does this small piece of code seem ok?

#21
or what about -- start with a current date / time / seconds / microsecond string
so that exact string will only occur once every microsecond and will never repeat
and then after the microsecond -- add a random string.
Reply

#22
(11-01-2015, 03:43 PM)cartalot Wrote: or what about -- start with a current date / time / seconds / microsecond string
so that exact string will only occur once every microsecond and will never repeat
and then after the microsecond -- add a random string.

This is what I suggested.
Reply

#23
Especially compared to all of the discussion about randomness, this is a minor item, but I would generally forego the extra variable and do something like this:

PHP Code:
$check 0;
while (
$check === 0) {
    
$code get_random_string();
    
$check $this->db->where('guest_code'$code)->count_all_results('guests');


or

PHP Code:
do {
    
$code get_random_string();
    
$check $this->db->where('guest_code'$code)->count_all_results('guests');
} while (
$check === 0); 
Reply

#24
(11-04-2015, 11:50 AM)mwhitney Wrote: Especially compared to all of the discussion about randomness, this is a minor item, but I would generally forego the extra variable and do something like this:

PHP Code:
$check 0;
while (
$check === 0) {
    
$code get_random_string();
    
$check $this->db->where('guest_code'$code)->count_all_results('guests');


or

PHP Code:
do {
    
$code get_random_string();
    
$check $this->db->where('guest_code'$code)->count_all_results('guests');
} while (
$check === 0); 

It has been awhile but I just had to reply on this.

Shouldn't it be

PHP Code:
while( $check === 

Because no match means $check remains 0 and the cycle is run again right? But we only want the cycle to rerun if a match was found setting $check = 1;
Reply

#25
Lol. Good spot. Actually it should be

PHP Code:
$check 1;
while(
 $check > 0 ) ... 

Because you might get more than one match.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.