Thread: generate a random password

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C++ beginner
    Join Date
    Jun 2004
    Posts
    66

    generate a random password

    Code:
    For this exercise creat a program that outputs a password 
    consisting of sequence of 8 randum upper or lowercase letters or 
    digits. Duplicate characters are permitted.
    My question is, that I'm not sure how to get this done. I have an idea though... but I'm not sure if it is a good way to do this. My idea was to generate at random, the corresponding decimal ASCII codes for the characters, and then use a static cast to make them type char. In doing so, they will be converted to characters... (right?) Well, that's my understanding of how that works, will that idea work? Or will the static cast not produce a character? Is this a good way to do this? Or should I think of a better solution (this one is a bit complicated - considering I'll have to acount for the leading zeroes on the corresponding ASCII decimal values from 000 (null) to 099 (c). Also, I'll have to filter out characters that are not letters or numbers.

    My guess, is that what I am thinking about, if even do able (think about my static cast) is too complicated for this seemingly easy problem. What do you all think? Is there an easier way to go about doing this?

    EDIT: If that way is doable (which I'm not sure it is, the static cast part I'm not sure of) ... would I have to account for the leading zeroes? or...?
    Last edited by mabufo; 02-21-2006 at 08:40 PM.
    Oh my goodness.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 05:51 PM
  2. Generate random numbers in Lucky7 project using C#
    By Grayson_Peddie in forum C# Programming
    Replies: 1
    Last Post: 04-11-2003, 11:03 PM
  3. auto generate password
    By Coconut in forum C Programming
    Replies: 4
    Last Post: 09-29-2002, 03:55 AM
  4. Random Password Generator v1.0 - download it
    By GaPe in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 08-18-2002, 01:27 AM
  5. Best way to generate a random double?
    By The V. in forum C Programming
    Replies: 3
    Last Post: 10-16-2001, 04:11 PM