Welcome Guest, Not a member yet? Register   Sign In
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, 02: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

(This post was last modified: 11-04-2015, 10:50 AM by mwhitney.)

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, 10: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




Theme © iAndrew 2016 - Forum software by © MyBB