Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

A random string

Posted on 1999-09-07
5
Medium Priority
?
199 Views
Last Modified: 2013-11-20
I need to make a random string. I have to make sure that each time it a different string. I thought to combine the date and the time to a string. How can I do it?
0
Comment
Question by:osnat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 4

Expert Comment

by:nil_dib
ID: 2026925
 int nStrLen = 10;
  string s;
  srand( (unsigned)time( NULL ) );  
   for( int i = 0;   i < nStrLen;i++ )    
         s += rand();

nil_dib
0
 

Author Comment

by:osnat
ID: 2026937
That will not promise me a DIFFERENT string EVERY time!
I thought to combine the date and the time, and since the time is changing I'll get every second a different string:
for example:
The date is 070999
The time is 10:00:00
So the final string is: 07099910:00:00
After 1 second time will be 10:00:01 so I'll get a new string: 07099910:00:01
This is what I want to do!
0
 
LVL 4

Accepted Solution

by:
nil_dib earned 200 total points
ID: 2026960
they are different: the date and time are calculated in the time() function!

srand( (unsigned)time( NULL ) );  
 

if you want the date and time as string:

CTime       time;
time = CTime::GetCurrentTime( );
CString s = t.Format( "%A, %B %d, %Y" );
// output in s:
// "Friday, March 19, 1999"



nil_dib
0
 
LVL 4

Expert Comment

by:nil_dib
ID: 2027016
for a string like 07099910:00:00
write

CString s = t.Format("%d%m%Y%H:%M:%S");


nil_dib
0
 
LVL 4

Expert Comment

by:nil_dib
ID: 2027217
why did you give a "C" ?
isn't the answer what you are looking for ???

nil_dib
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question