Velocity Reviews > Positive random number

# Positive random number

deepak
Guest
Posts: n/a

 12-18-2007
Hi,

Can someone give the standard function which can create positive
integer value in C?

Thanks,
Deepak

Richard Heathfield
Guest
Posts: n/a

 12-18-2007
deepak said:

> Hi,
>
> Can someone give the standard function which can create positive
> integer value in C?

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999

santosh
Guest
Posts: n/a

 12-18-2007
deepak wrote:

> Hi,
>
> Can someone give the standard function which can create positive
> integer value in C?
>
> Thanks,
> Deepak

Look-up rand.

divyank.rastogi@gmail.com
Guest
Posts: n/a

 12-18-2007
On Dec 18, 4:27 am, santosh <(E-Mail Removed)> wrote:
> deepak wrote:
> > Hi,

>
> > Can someone give the standard function which can create positive
> > integer value in C?

>
> > Thanks,
> > Deepak

>
> Look-up rand.

You may want to man for rand series entirely; e.g. you may want to use
srand, and seed it with something like your system time to generate
random sequences, etc.

Guest
Posts: n/a

 12-18-2007
deepak wrote:
> Hi,
>
> Can someone give the standard function which can create positive
> integer value in C?

There is no standard C function that creates numbers out of nothing.

If you are rather looking for a pseudo-random generator, see the C FAQ.

--
Tor <(E-Mail Removed) | tr i-za-h a-z>

CBFalconer
Guest
Posts: n/a

 12-19-2007
> deepak wrote:
>
>> Can someone give the standard function which can create positive
>> integer value in C?

>
> There is no standard C function that creates numbers out of nothing.

However, the sequence "i = N;" is fairly safe, as long as N
represents a sequence of numeric digits (not including the '-'
sign) which represents a value <= INT_MAX. This even has the
elegant characteristic of allowing you to pick your own integer

Another sophisticated sequence (which is not always possible) is:

if (i < 0) i = -i;

HTH

--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Jack Klein
Guest
Posts: n/a

 12-19-2007
On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
<(E-Mail Removed)> wrote in comp.lang.c:

> Hi,
>
> Can someone give the standard function which can create positive
> integer value in C?

Other's have talked about "rand()", but I don't see anything in your
post that requires it. Here's a function guaranteed to meet the

int create_positive_integer_value_in_C(void)
{
return 42;
}

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html

Keith Thompson
Guest
Posts: n/a

 12-19-2007
Jack Klein <(E-Mail Removed)> writes:
> On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
> <(E-Mail Removed)> wrote in comp.lang.c:
>> Can someone give the standard function which can create positive
>> integer value in C?

>
> Other's have talked about "rand()", but I don't see anything in your
> post that requires it.

[...]

The subject was "Positive random number". That information should
have been in the body of the original post.

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Looking for software development work in the San Diego area.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

jaysome
Guest
Posts: n/a

 12-19-2007
On Tue, 18 Dec 2007 20:30:18 -0600, Jack Klein <(E-Mail Removed)>
wrote:

>On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
><(E-Mail Removed)> wrote in comp.lang.c:
>
>> Hi,
>>
>> Can someone give the standard function which can create positive
>> integer value in C?

>
>Other's have talked about "rand()", but I don't see anything in your
>post that requires it. Here's a function guaranteed to meet the
>
>int create_positive_integer_value_in_C(void)
>{
> return 42;
>}

Definitely *not* guaranteed.

In C99, section 5.2.4.1 Translation limits:

"The implementation shall be able to translate and execute at least
one program that contains at least one instance of every one of the
following limits:

....

31 significant initial characters in an external identifier..."

The identifier "create_positive_integer_value_in_C" is an external
identifier with 34 characters, and thus exceeds the minimum number of
characters *guaranteed* to be accepted by the standard. In C90, the
minimum was a paltry six characters.

Now, an identifier such as "create_positive_int_value_in_C" (30
characters) is acceptable in C99, but not necessarily in C90, though
arguably it is acceptable in most--if not all--C90 compilers in the
real world (for that matter, so is
"create_positive_integer_value_in_C" :^)

--
jay

santosh
Guest
Posts: n/a

 12-19-2007
jaysome wrote:

> On Tue, 18 Dec 2007 20:30:18 -0600, Jack Klein <(E-Mail Removed)>
> wrote:
>
>>On Tue, 18 Dec 2007 00:43:10 -0800 (PST), deepak
>><(E-Mail Removed)> wrote in comp.lang.c:
>>
>>> Hi,
>>>
>>> Can someone give the standard function which can create positive
>>> integer value in C?

>>
>>Other's have talked about "rand()", but I don't see anything in your
>>post that requires it. Here's a function guaranteed to meet the
>>
>>int create_positive_integer_value_in_C(void)
>>{
>> return 42;
>>}

>
> Definitely *not* guaranteed.
>
> In C99, section 5.2.4.1 Translation limits:
>
> "The implementation shall be able to translate and execute at least
> one program that contains at least one instance of every one of the
> following limits:
>
> ...
>
> 31 significant initial characters in an external identifier..."
>
> The identifier "create_positive_integer_value_in_C" is an external
> identifier with 34 characters, and thus exceeds the minimum number of
> characters *guaranteed* to be accepted by the standard. In C90, the
> minimum was a paltry six characters.

What part of "31 significant initial characters" did you not understand.
Jack's function name will only cause problems if he happened to have
defined another identifier with the same sequence of 31 initial
characters.