6 Replies - 216 Views - Last Post: 06 December 2012 - 05:40 PM Rate Topic: -----

#1 hotshotennis  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 133
  • Joined: 07-October 12

Assigning random digits to a string

Posted 06 December 2012 - 05:01 PM

StringBuilder tempString = new StringBuilder();
tempString = tempString.append(Math.random() * (9 - 0 + 1) + 0); 



-I'm trying to assign 9 random digits(one char at a time) to a local StringBuilder object. But its not working. The number I get when I print tempString is:
7897 893. 9660 7073 7313 6326 1

And I want something like so:
7897 8931 4062 1219

Could someone please tell me what is wrong?
Thank you for your time!

Is This A Good Question/Topic? 0
  • +

Replies To: Assigning random digits to a string

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2816
  • View blog
  • Posts: 11,924
  • Joined: 20-September 08

Re: Assigning random digits to a string

Posted 06 December 2012 - 05:21 PM

Quote

-I'm trying to assign 9 random digits

And I want something like so:
7897 8931 4062 1219
Err.. that's 16 digits ...
Was This Post Helpful? 0
  • +
  • -

#3 hotshotennis  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 133
  • Joined: 07-October 12

Re: Assigning random digits to a string

Posted 06 December 2012 - 05:23 PM

View Postg00se, on 06 December 2012 - 05:21 PM, said:

Quote

-I'm trying to assign 9 random digits

And I want something like so:
7897 8931 4062 1219
Err.. that's 16 digits ...


-Don't worry about it. Its later appended with something else. This is just a tiny snippet of my program.
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2816
  • View blog
  • Posts: 11,924
  • Joined: 20-September 08

Re: Assigning random digits to a string

Posted 06 December 2012 - 05:26 PM

Sorry - i don't understand
Was This Post Helpful? 0
  • +
  • -

#5 hotshotennis  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 133
  • Joined: 07-October 12

Re: Assigning random digits to a string

Posted 06 December 2012 - 05:30 PM

View Postg00se, on 06 December 2012 - 05:26 PM, said:

Sorry - i don't understand


I'm creating a credit card number, that tempString is only a part of that number. For example:
 accountNum = tempString.toString();


I also have an issuer ID. when I combine the accountNum(which is a copy of my tempString that I'm working on) I get my whole credit card number (all 16 digits).
Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2816
  • View blog
  • Posts: 11,924
  • Joined: 20-September 08

Re: Assigning random digits to a string

Posted 06 December 2012 - 05:33 PM

Please restate your question - clearly
Was This Post Helpful? 0
  • +
  • -

#7 hotshotennis  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 133
  • Joined: 07-October 12

Re: Assigning random digits to a string

Posted 06 December 2012 - 05:40 PM

View Postg00se, on 06 December 2012 - 05:33 PM, said:

Please restate your question - clearly


I figured it out! Sorry for bothering you. I just had to cast my math.random properly to an int.
But thank you for your time anyway!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1