Sponsored Content
Top Forums Programming generating 16 digit random number in C Post 302344628 by ajaysahoo on Monday 17th of August 2009 07:17:44 AM
Old 08-17-2009
thanks jim...
its generating 16 digit no, but could please tell me that how the nos can be generated in double format.

i tried using atof() , but did nt work.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

generating random numbers with hamming distance 4

Hi I want to genrate 10 random 32 bit binary numbers with hamming distance 4 and 8. 11010110010101010101010101010101 11010110010101010100010101010010 if we look carefully at these two binary numbers they differ at 4 places hence hamming distance 4. Now I want to genrate these numbers... (2 Replies)
Discussion started by: hack_tom
2 Replies

2. Shell Programming and Scripting

Generating random number within a specific range (0.5-1.5)

Hello, need a way to generate numbers within 0.5-1.5 range Has to be totally random: 0.6 1.1 0.8 1.5 0.6 and so on.... How to? (10 Replies)
Discussion started by: TehOne
10 Replies

3. Shell Programming and Scripting

Generating random numbers

Hi, I am having trouble with generating random numbers. can this be done with awk? So I have a file that looks like this: 23 30 24 40 26 34 So column1 is start and column2 is end. I want to generate 3 random #'s between start and stop: So the output will look like this: ... (9 Replies)
Discussion started by: phil_heath
9 Replies

4. Programming

C Help; generating a random number.

Im new to C, and Im having a hard time getting a random number. In bash, I would do something similar to the following to get a random number; #!/bin/bash seed1=$RANDOM seed2=$RANDOM seed3=$RANDOM SEED=`expr $seed1 * $seed2 / $seed3` echo ${SEED%.*} Now, in online examples... (4 Replies)
Discussion started by: trey85stang
4 Replies

5. Programming

Generating Random Number in Child Process using Fork

Hello All, I am stuck up in a program where the rand functions ends up giving all the same integers. Tried sleep, but the numbers turned out to be same... Can anyone help me out how to fix this issue ? I have called the srand once in the program, but I feel like when I call fork the child process... (5 Replies)
Discussion started by: manisum
5 Replies

6. Shell Programming and Scripting

Generate 16 digit positive random Numbers

Hi Unix Gurus, I have a requirement to generate positive random 16 and 13 digit numbers. Here is the script I have so far..... number=$RANDOM$RANDOM$RANDOM$RANDOM; let "number %= 10000000000000"; echo $number But sometimes it is generating negative numbers and also 15 digit... (8 Replies)
Discussion started by: scorpioraghu
8 Replies

7. Shell Programming and Scripting

Generating Random Number in certain range

Hi there I am trying to generate a random number between 40 and 70 using the shell here is my code so far and it keeps going above 70. all help much appreciated! comp=$(( RANDOM%70+40 )) echo $comp (4 Replies)
Discussion started by: faintingquiche
4 Replies

8. Shell Programming and Scripting

Random number generating script?

Having a hard time with this. Very new to scripting and linux. Spent all sunday trying to do this. Appreciate some help and maybe help breaking down what the syntax does. Create a Bash program. It should have the following properties • Creates a secret number between 1 and 100 i. The... (3 Replies)
Discussion started by: LINUXnoob15
3 Replies

9. Shell Programming and Scripting

Generating a Random String of 'n' length

Hi, How can I generate a string of random characters (alpha+numeric) of a particular length ? For e.g. for n=5, output = 'kasjf' n=10, output = 'hedbcd902k' Also, please let me know if random (valid) dates could also be generated. Thanks (7 Replies)
Discussion started by: rishigc
7 Replies

10. Shell Programming and Scripting

Generating a POSIX random number?

Hi Guys and gals... As you know I am getting to grips with POSIX and hit this stumbling block. Generating two random numbers 0 to 255 POSIXly. Speed in not important hence the 'sleep 1' command. I have done a demo that works, but it sure is ugly! Is there a better way? #!/bin/sh # Random... (12 Replies)
Discussion started by: wisecracker
12 Replies
atof(3) 						     Library Functions Manual							   atof(3)

NAME
atof, strtod, strtof, strtold - Converts a character string to a double-precision floating-point value LIBRARY
Standard C Library (libc.a) SYNOPSIS
#include <stdlib.h> double atof( const char *nptr); double strtod( const char *nptr, char **endptr); float strtof( const char *nptr, char **endptr); long double strtold( const char *nptr, char **endptr); PARAMETERS
Points to the character string to convert. Specifies either a null value, a pointer to the character that ended the scan, or a pointer to a null value. DESCRIPTION
The atof() function converts, to a double floating-point value, the string pointed to by the nptr parameter - up to the first character that is inconsistent with the format of a floating-point number. Leading space characters are ignored. A call to this function is equiva- lent to a call to strtod(nptr, (char **) NULL), except for error handling. When the value cannot be represented, the result is undefined. The strtod(), strtof(), and strtold() functions convert the initial portion of the string pointed to by the nptr parameter to double, float, and long double representation, respectively. First, the input string is decomposed into the following three parts: An initial, possibly empty, sequence of space characters (as specified by the isspace() function). A subject sequence interpreted as a floating-point constant. A final string of one or more unrecognized characters, including the terminating null character of the input string. After decomposition of the string, the subject sequence is converted to a floating-point number and the resulting value is returned. A subject sequence is defined as the longest initial subsequence of the input string, starting with the first non-space character, that is of the expected form. The expected form and order of the subject sequence is: An optional plus (+) or minus (-) sign. A sequence of digits optionally containing a radix character. An optional exponent part. An exponent part consists of e or E, followed by an optional sign, which is followed by one or more decimal digits. The subject sequence contains no characters when the input string is empty or consists entirely of space characters, or when the first non- space character is other than a sign, a digit, or a radix character. For the strtod(), strtof(), and strtold() functions, when the value of the endptr parameter is not (char**) NULL, a pointer to the charac- ter that terminated the scan is stored at *endptr. When a floating-point value cannot be formed, *endptr is set to nptr. The strings NaN ("not a number"), Inf, and Infinity (the case of the characters does not matter) are recognized as valid only when the pro- gram is compiled with the -ieee option. NOTES
The setlocale() function may affect the radix character used in the conversion result. Full use RETURN VALUES
When the string is empty or begins with an unrecognized character, +0.0 is returned as the floating-point value. If the calling routine is compiled with IEEE floating point enabled (-ieee flag), errno will be set to ERANGE if the conversion underflows to zero. Similarly, if the value overflows, ERANGE will be set and a properly signed infinity will be returned. If the calling routine is not compiled with IEEE floating point enabled, any underflow will cause errno to be set to ERANGE and a properly signed zero to be returned. An overflow will cause errno to be set to ERANGE and will return a properly signed DBL_MAX, FLOAT_MAX, or LDBL_MAX. Upon successful completion, all of the functions return the converted floating-point value. ERRORS
If the atof(), strtod(), strtof(), or strtold() function fails, errno may be set to the following value: The input string is out of range (that is, the subject sequence cannot be converted to a floating-point value without causing underflow or overflow). RELATED INFORMATION
Functions: atoi(3), scanf(3) delim off atof(3)
All times are GMT -4. The time now is 09:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy