[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Newer to Ruby

Kwhamec Rojas

12/7/2005 8:47:00 PM

Hi. I am new to Ruby and new to programming altogether, but I am really
trying to learn as fast as I can.

So here's my problem: I need to be able to generate a random nine digit
number. The first number cannot be 9,8 or 7.

I am using Watir to test a site, but I will need to randomly generate
this number or the test will be rejected. Thank you very much for
whatever help you can give me.

--
Posted via http://www.ruby-....


10 Answers

James Gray

12/7/2005 8:51:00 PM

0

On Dec 7, 2005, at 2:47 PM, Kwhamec Rojas wrote:

> Hi. I am new to Ruby and new to programming altogether, but I am
> really
> trying to learn as fast as I can.
>
> So here's my problem: I need to be able to generate a random nine
> digit
> number. The first number cannot be 9,8 or 7.
>
> I am using Watir to test a site, but I will need to randomly generate
> this number or the test will be rejected. Thank you very much for
> whatever help you can give me.

See if this gives you some ideas:

>> digits = [rand(7)] + Array.new(8) { rand(10) }
=> [5, 6, 1, 2, 5, 4, 7, 1, 1]

James Edward Gray II


Derek Chesterfield

12/7/2005 8:52:00 PM

0

rand(700000000)

On 7 Dec 2005, at 8:47pm, Kwhamec Rojas wrote:

> I need to be able to generate a random nine digit
> number. The first number cannot be 9,8 or 7.



Caleb Tennis

12/7/2005 9:01:00 PM

0


> >> digits = [rand(7)] + Array.new(8) { rand(10) }
>
> => [5, 6, 1, 2, 5, 4, 7, 1, 1]

I was thinking:

( [rand(6)+1] + Array.new(8) { rand(10) }).to_s.to_i


Kwhamec Rojas

12/7/2005 9:07:00 PM

0

bbazzarrakk wrote:
> On Dec 7, 2005, at 2:47 PM, Kwhamec Rojas wrote:
>
>> whatever help you can give me.
> See if this gives you some ideas:
>
> >> digits = [rand(7)] + Array.new(8) { rand(10) }
> => [5, 6, 1, 2, 5, 4, 7, 1, 1]
>
> James Edward Gray II

Thanks a lot. This will more than do.

--
Posted via http://www.ruby-....


dblack

12/7/2005 9:33:00 PM

0

Jeff Wood

12/7/2005 9:58:00 PM

0

number = ( rand( 599999999 ) + 100000000 )

... should always generate a 9 digit number.

j.

On 12/7/05, Kwhamec Rojas < bedeviledme@fastmail.fm> wrote:
>
> Hi. I am new to Ruby and new to programming altogether, but I am really
> trying to learn as fast as I can.
>
> So here's my problem: I need to be able to generate a random nine digit
> number. The first number cannot be 9,8 or 7.
>
> I am using Watir to test a site, but I will need to randomly generate
> this number or the test will be rejected. Thank you very much for
> whatever help you can give me.
>
> --
> Posted via http://www.ruby-....
>
>


--
"Remember. Understand. Believe. Yield! -> http://ruby-lang...

Jeff Wood

Jeff Wood

12/7/2005 10:11:00 PM

0

heh. sorry d.black didn't see you'd already posted it.

j.

On 12/7/05, Jeff Wood <jeff.darklight@gmail.com> wrote:
>
> number = ( rand( 599999999 ) + 100000000 )
>
> ... should always generate a 9 digit number.
>
> j.
>
> On 12/7/05, Kwhamec Rojas < bedeviledme@fastmail.fm> wrote:
> >
> > Hi. I am new to Ruby and new to programming altogether, but I am really
> >
> > trying to learn as fast as I can.
> >
> > So here's my problem: I need to be able to generate a random nine digit
> > number. The first number cannot be 9,8 or 7.
> >
> > I am using Watir to test a site, but I will need to randomly generate
> > this number or the test will be rejected. Thank you very much for
> > whatever help you can give me.
> >
> > --
> > Posted via http://www.ruby-....
> >
> >
>
>
> --
> "Remember. Understand. Believe. Yield! -> http://ruby-lang...
>
> Jeff Wood




--
"Remember. Understand. Believe. Yield! -> http://ruby-lang...

Jeff Wood

rcoder@gmail.com

12/8/2005 2:42:00 AM

0

Just out of curiousity, what is the basic test case for this? I only
ask because an algorithm to generate 9-digit numbers that don't begin
with 7, 8, or 9 sounds awfully useful to generate bogus US Social
Security Numbers.

I don't want to sound paranoid or anything; it just struct me as an odd
coincidence...

-rcoder

rcoder@gmail.com

12/8/2005 3:02:00 AM

0

Just out of curiousity, what is the basic test case for this? I only
ask because an algorithm to generate 9-digit numbers that don't begin
with 7, 8, or 9 sounds awfully useful to generate bogus US Social
Security Numbers.

I don't want to sound paranoid or anything; it just struct me as an odd
coincidence...

-rcoder

Kwhamec Rojas

12/14/2005 12:12:00 PM

0

rcoder wrote:
> Just out of curiousity, what is the basic test case for this? I only
> ask because an algorithm to generate 9-digit numbers that don't begin
> with 7, 8, or 9 sounds awfully useful to generate bogus US Social
> Security Numbers.
>
> I don't want to sound paranoid or anything; it just struct me as an odd
> coincidence...
>
> -rcoder

That is exactly what I need to use it for. The site I am supposed to
test involves financial transactions that are logged under both, email
and ss#. Generating random emails is no problem, as they are all
directed to me anyway. The problem was generating the random ss#.

We have a perl script that dips into our own database and uses existing
accounts to generate phantom accounts and test new features, but
everyone wants to move over to Ruby.

Coincidences only happen to people who don't pay attention. :)

--
Posted via http://www.ruby-....