Hey!   Someone worked hard on String::rjust()!  Put it to good use!  :)
 
---Michael B.


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Sergio Pinon
Sent: January 23, 2006 2:57 PM
To: [email protected]
Subject: Re: [Wtr-general] Random number generation.

I don’t know too much about the first problem that you are having but as for your second one try this. I changed the max to be no higher than 99999 and then you get a maximum of 5 digits. If you have less then I just concat zeros on the end. Hope this helps.

 

Sergio

 

def Random_number

   $rand_num = rand(max=99999).to_s()

  

   while $rand_num.length < 5

            $rand_num << "0"

   end

        puts ("tester"+ ($rand_num))

       

   return $rand_num

end


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent: Monday, January 23, 2006 11:31 AM
To: [email protected]
Subject: [Wtr-general] Random number generation.

 

I have 2 questions:

 

Can I use method names other then "test_sometest" in my script. For example, I have a method that performs a calculation and returns a value and passes that value to test method. Unless I rename my calculation method as "test_calculation" the method is not executed. I know that my class is inheriting from test::unit, but do I need to precede every method name with "test"?

 

Secondly, I am trying to generate test users for my test by generating a random number and the concatenating that number to a string "test" so that the result is "test12345", for example.

 

I'm using rand(max-0) to generate the number, but it returns a big number. So I tried stripping the number and then concatenating but it didn't work. Ultimately, I would like to have generate names with 5 digits randomly like the example above. Any ideas?

 

def Random_name
   $rand_num = rand(max=0)
   $rand_num =~ /^0???/

   $rand_user = $rand_num.to_s
        puts ("tester"+ ($rand_user))
        
   return $rand_user
  end

 

 

 

_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to