473,396 Members | 1,924 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,396 software developers and data experts.

How to generate random characters in c language?

How can i generate random characters in c language?
i hope for your responses. Thanks. :)
Mar 16 '11 #1
5 8776
Meetee
931 Expert Mod 512MB
There's a rand() function for generating random numbers/characters.
Mar 16 '11 #2
donbock
2,426 Expert 2GB
I assume you only want to select among the printable subset of character values. In general, construct an array that contains all valid values, then use rand() to randomly select an index into the array.
Mar 16 '11 #3
weaknessforcats
9,208 Expert Mod 8TB
Or since you know that all characters are between 'A' and 'z', keep fetching random numbers until you get one in this range.
Mar 16 '11 #4
you can use random() to generate random number then take mod with 26 and add 65 to it to generate character between 'A' and 'Z' or add 97 to generate character between 'a' and 'z'.
Mar 16 '11 #5
donbock
2,426 Expert 2GB
Arvind's suggestion assumes the platform uses ASCII character encoding. Most platforms do use ASCII so this isn't an unreasonable assumption; but you should always know when you're relying on an assumption.
Mar 18 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: ,hj | last post by:
From: ",hj" <webmaster@mail.com> Subject: Losing random characters in HTML email Date: 28 November 2003 17:21 I've narrowed down my code as much as I can so that I can show you this bug. The...
5
by: Yudan YI \(OSU\) | last post by:
I want to generate random data from a normal distribution, while I checked the functions, and I found rand(), which returns a pseudorandom integer between zero and RAND_MAX. I am not sure how to...
4
by: Marc Dansereau | last post by:
Hi all, I wonder what is the most efficient way to generate random point on a line defined by 2 double points (x0,y0) and (x1,y1). Here is the pseudocode of my method : for each point {...
6
by: comp.lang.php | last post by:
/** * Generate the random security image * * @access public * @param $willUseFilePath (default false) boolean to determine if you will be using a file path * @param mixed $filePath (optional)...
3
by: pedestrian via DotNetMonster.com | last post by:
Let's say I declares an array of string (of size 1000), how to fill every elements of it with random characters? Dim myStrArray(999) As String ... Thanks... -- Pedestrian, Penang.
0
sashi
by: sashi | last post by:
Generate Random Password In the course of programming you may have cause to generate a password. The following function will generate a password of randomly selected characters up to a maximum of...
9
by: Chelong | last post by:
Hi All I am using the srand function generate random numbers.Here is the problem. for example: #include<iostream> #include <time.h> int main() {
24
by: pereges | last post by:
I need to generate two uniform random numbers between 0 and 1 in C ? How to do it ? I looked into rand function where you need to #define RAND_MAX as 1 but will this rand function give me ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.