473,386 Members | 1,842 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

random string generator library!

Hello All,

I wanna write an small game which need to generate a random string each
time. It should go like this.

TCHAR tmpStr[_MAX_PATH];
unsigned int nLen=50;
TCHAR seedStr=_T("dummy seed");

int ret = randomstr(tmpStr, /*returned random string*/
nLen /*length of returned string*/,
seedStr/*a seed for string producing*/);

Is there any library available or any helpful information?

TIA

Phipps
Jul 22 '05 #1
2 2602
On Fri, 09 Jan 2004 09:52:19 +0800, Phipps Xue wrote:
Hello All,

I wanna write an small game which need to generate a random string each
time. It should go like this.

TCHAR tmpStr[_MAX_PATH];
unsigned int nLen=50;
TCHAR seedStr=_T("dummy seed");

int ret = randomstr(tmpStr, /*returned random string*/
nLen /*length of returned string*/,
seedStr/*a seed for string producing*/);

Is there any library available or any helpful information?


I'm not aware of any library. Also, you don't give any information about
what goes in the string. It probably is pretty easy to write yourself if
the requirements on the string are easy.

You don't need a seedstring, just seed the random generator.

Something like:

int randomstr(char *buf, size_t len)
{
int i=0;
char c;
if (len==0) return 1;
while (i<len) {
c = rand() % SCHAR_MAX; /* look at the FAQ for better techniques */
if (isprint(c)) {
*buf++ = c;
i++;
}
}
return 0;
}

HTH,
M4

Jul 22 '05 #2
You could use simple permutations of the seed string, if that's
sufficient for your needs. There are permutation algorithms in the STL.

Phipps Xue wrote:
Hello All,

I wanna write an small game which need to generate a random string each
time. It should go like this.

TCHAR tmpStr[_MAX_PATH];
unsigned int nLen=50;
TCHAR seedStr=_T("dummy seed");

int ret = randomstr(tmpStr, /*returned random string*/
nLen /*length of returned string*/,
seedStr/*a seed for string producing*/);

Is there any library available or any helpful information?

TIA

Phipps


Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: trs1800 | last post by:
/*i think someone should use this to name their baby*/ import java.util.Random; public class name { public static void main(String args) { String string1; char char1 = 7; string1 = " "; int...
1
by: Brandon Michael Moore | last post by:
I'm trying to test a web application using a tool written in python. I would like to be able to generate random values to put in fields. I would like to be able to generate random dates (in a...
4
by: Jonathan Burd | last post by:
Greetings everyone, Here is a random string generator I wrote for an application and I'm wondering about the thread-safety of this function. I was told using static and global variables cause...
15
by: felixnielsen | last post by:
This is something i have done before and i know its pretty simple, however i cant remember how it works exactly, and i need it i kinda hurry, so if someone would be so nice to drop a random number...
8
by: asdf | last post by:
I want a random number generator, the random number should be subject a uniform distribution in . Could you please give me some hints? Thanks.
3
by: Daniel | last post by:
Hey guys Using Random(), how random is it, is it possible to be predicted? I have a requirement for a very good random number generator. I was doing something such as: Random randomSeed = new...
38
by: Andrea | last post by:
Hi, Anyone could me suggest how to create a function that generates a random string? The function should be: int _RandomString(char** str,int len); so, it takes an empty string str and it puts...
6
by: badcrusher10 | last post by:
Hello. I'm having trouble figuring out what to do and how to do.. could someone explain to me what I need to do in order to work? THIS IS WHAT I NEED TO DO: Professor Snoop wants a program...
11
TTCEric
by: TTCEric | last post by:
This will be original. I promise. I cannot get the random number generator to work. I tried seeding with Date.Now.Milliseconds, it still results in the same values. What I have are arrays...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.