Newer to Ruby

K

Kwhamec Rojas

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.
 
J

James Edward Gray II

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
 
D

dblack

Hi --

rand(700000000)

That won't always give you a nine-digit number (I'm assuming that
starting with one or more 0's doesn't count... though it's not 100%
clear).

Since the useful range is 100000000 to 699999999, you could do:
rand(599999999) + 100000000


David
 
J

Jeff Wood

------=_Part_5793_8984449.1133992692273
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

number =3D ( rand( 599999999 ) + 100000000 )

... should always generate a 9 digit number.

j.

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.


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

Jeff Wood

------=_Part_5793_8984449.1133992692273--
 
J

Jeff Wood

------=_Part_6069_7778918.1133993453857
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

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

j.

number =3D ( rand( 599999999 ) + 100000000 )

... should always generate a 9 digit number.

j.




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

Jeff Wood

------=_Part_6069_7778918.1133993453857--
 
R

rcoder

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
 
R

rcoder

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
 
K

Kwhamec Rojas

rcoder said:
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. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,048
Members
47,646
Latest member
xayaci5906

Latest Threads

Top