11-30-2009
Quote:
Originally Posted by
Corona688
It's saying it's not constant because it's not.
You can't initialize variables from non-constant things, i.e. functions in C. Initialize it once at the beginning of main().
I tried deleting the RANDOM function and placing its contents inside main, then use a variable to feed the random number to the other functions. This works yet it defeats the whole purpose of using a function to generate a random number.
This is for a website, so having to include this bunch of code inside every single webpage is kind of inefficient... That is why I wanted to use a single function.
Is there no other way of achieving this by reusing the RANDOM function???
10 More Discussions You Might Find Interesting
1. Programming
How to generate a random integer with specific range(for example, from 1 to 1000)?
Also, how to convert a floating point number into a integer? (2 Replies)
Discussion started by: MacMonster
2 Replies
2. Programming
I use standard C random number generation logic in my application.
long nCounter;
long lRndNo;
char rand;
srand48(nCounter);
lRndNo = lrand48();
sprintf(rand,"%010.10d",lRndNo);
However we always find that the rand generated starts with '0','1' or '2'. I could not logically prove if... (1 Reply)
Discussion started by: asutoshch
1 Replies
3. Programming
Hi...How can I generate random numbers between a given range ...preferably between 1 and 100...in UNIX C programming...?
I tried out functions like rand(),drand48() etc but didnt get satisfactory results...
Thanks a lot in advance.......... (1 Reply)
Discussion started by: tej.buch
1 Replies
4. Shell Programming and Scripting
HI
please help me in solving this issue.
I have a shell script which consists of ten statemnts ( i mean 10 executable statments)...........and if i run that script the 10 statmenst will execute continously ............
But now my probelm is i have to write another script --> to... (0 Replies)
Discussion started by: lalitka
0 Replies
5. Shell Programming and Scripting
How do I create a random number between 1 and 10 in kornshell? (2 Replies)
Discussion started by: dangral
2 Replies
6. Programming
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
7. Programming
I saw this formula to generate random number between two specified values in shell script.the following.
$(((RANDOM%(max-min+divisibleBy))/divisibleBy*divisibleBy+min))
Give a example in book.
Generate random number between 6 and 30.like this.
$(((RANDOM%30/3+1)*3))
But I have a... (1 Reply)
Discussion started by: luoluo
1 Replies
8. Shell Programming and Scripting
Hello folks,
i have number for example 10 and i want to divide into 4 random pieces that may be (6+2+1+1). How can i do this via script i have random number 234951 and i want to divide into 31 pieces. (6 Replies)
Discussion started by: learnbash
6 Replies
9. Shell Programming and Scripting
Hi,
I'm trying to create a script that will print random numbers with length of three.
Below is the expected out.
928-377-899
942-458-310
951-948-511
962-681-415
995-161-708
997-997-209
thanks (4 Replies)
Discussion started by: reignangel2003
4 Replies
10. Programming
How can I choose randomly the row numbers of my file in awk? (4 Replies)
Discussion started by: Homa
4 Replies
LEARN ABOUT DEBIAN
crypt::random::source::factory
Crypt::Random::Source::Factory(3pm) User Contributed Perl Documentation Crypt::Random::Source::Factory(3pm)
NAME
Crypt::Random::Source::Factory - Load and instantiate sources of random data
SYNOPSIS
use Crypt::Random::Source::Factory;
my $f = Crypt::Random::Source::Factory->new;
my $strong = $f->get_strong;
my $weak = $f->get_weak;
my $any = $f->get;
DESCRIPTION
This class implements a loading and instantiation factory for Crypt::Random::Source objects.
If $ENV{CRYPT_RANDOM_NOT_PLUGGABLE} is set then only a preset list of sources will be tried. Otherwise Module::Find will be used to locate
any installed sources, and use the first available one.
METHODS
get %args
Instantiate any random source, passing %args to the constructor.
The "type" argument can be "weak", "strong" or "any".
get_weak %args
get_strong %args
Instantiate a new weak or strong random source.
AUTHOR
Yuval Kogman <nothingmuch@woobling.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Yuval Kogman.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
perl v5.14.2 2011-01-05 Crypt::Random::Source::Factory(3pm)