# Thread: Random character generator algorithm

1. ## Random character generator algorithm

Will someone please critique my algorithm/plan?

I need to write a program that will generate random characters (they can be either numbers, or upper or lower case letters) in the following format u328-iK23-o32k-A28j.

My plan is to get a clock() reading after the user has entered a prompt, and use that to generate a random character. After the first and every subsequent random character is generated, I plan to use the clock at that point in the program to generate another one. Is this legitimate? Any comments, suggestions, or recommendations?

Note: I need to do this without using any of the random number functions

2. How do you plan on using the clock to generate the random numbers? One thing to watch for is that if you generate all the numbers at roughly the same time each with a call to the clock, you'll get the same random numbers. Also, depending on what you do with the clock, you could end up with what looks like 1112-2233-3444-5556 or something similar.

If you want to use the clock before each number, you need to make sure there is a lag between each clock call so they aren't called within the same millisecond or so.

3. Are you allowed to write your own random function?

Code:
```unsigned int my_rand()
{
signed long param[]  = { std::time(NULL), 12345 };
static signed long seed = (seed * param[1] + param[2]) % 2147483647;
return static_cast<unsigned int>(seed / 3);
}```

4. I am allowed to make my own functions, but I don't think I'm allowed to use the time function ( don't know what it is either, I'm only familiar with clock() ).

I was planning to store the characters in an array somehow. For example have the clock reading correspond to an array element. I guess I should write code that manipulates the clock reading every time the code generates a character?

5. Why don't you just use rand() to generate a mix of random numbers between the ASCII value of 'a' and the ASCII value of 'z',and random numbers between 0 and 9, and use
srand(time(0)) to randomize?
I think that's simple, isn't that what you want?

6. I gotta write this program without using rand() because it's an assignment for an intro. to computing class...we haven't disccused rand().

7. well tell then that you are way ahead of the rest and that you know rand(), and that its really not that hard.

if you dont know rand(), are you capable of making your own radom number function? is this an impossiable assignment?

8. If you want it to be simple, just take the current time and make some simple mathimatical operations, on it and you'll have a ramdom number...
The use the % operator to have it limtted between two numbers.
For example:
(any number)%10 -> will be between 0 and 9
5 + (any number)%10 -> will be betwenn 5 and 14

Is that what you want?