can any one tell me how to create integer random no between 10 to 40 in C language.When i m using random() or rand() functions they r creting some
long int which is not required
Divide the random number by 31 ( 10 through 40) take the remainder and add 10.
Create an array of 31 entries, run 1,000,000 iterations and count how many times each number appears to see if you have 25000 of each number, or what the deviation is.
Why the resule is being divided by 30 to get the result & added to 10.
How to reach the above decision.
Because a random number between 10 and 40 was requested - the original result (which would be between 0 and 30) is just shifted by adding 10.
Cheers
ZB
can any one tell me how to create integer random no between 10 to 40 in C language.
Quote:
Originally Posted by jgt
Divide the random number by 31 ( 10 through 40) take the remainder and add 10.
Quote:
Originally Posted by ilko_partizan
this is not the way you should create a random number between 30 and 40.
a correct way is
you should not use the % operator to constract a random number from the last digits of a a random number generator. most random generators are neither contructed that their last digits are random nor are they testet against this assumption. They are constructed and tested that the leading digits are random.
rand() gives a random number bertween 0 and RAND_MAX
rand()/(RAND_MAX +1.0) gives a float random number greater or equal 0 and less then 1
(rand()/(RAND_MAX +1.0))*11 gives a random number greater or equal 0 and less then 11
(int)((rand()/(RAND_MAX +1.0))*11) gives a random number from the set {0,...,10}
finally 30+(int)((rand()/(RAND_MAX +1.0))*11) gives a random number from the set {30,...,40}
File 1 contains the list of words that needed to be randomly paired:
Tiger
Cat
Fish
Frog
Dog
Mouse
Elephant
Monkey
File 2 contains the pairs that should not be used (in any solution) during random pairing.
Elephant-Dog
Cat-Fish
Monkey-Frog
Dog-Elephant, Fish-Cat, Frog-Monkey... (1 Reply)
I have created one file that contains all the necessary info in it to create a download link. In each of the lines /results/analysis/output/Home/Auto_user_S5-00580-6-Medexome_67_032/plugin_out/FileExporter_out.67... (8 Replies)
Need to use dd to generate a large file from a sample file of random data. This is because I don't have /dev/urandom.
I create a named pipe then:
dd if=mynamed.fifo do=myfile.fifo bs=1024 count=1024
but when I cat a file to the fifo that's 1024 random bytes:
cat randomfile.txt >... (7 Replies)
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)
first off let me introduce myself. My name is Eric and I am new to linux, I am taking an advanced linux administration class and we are tasked with creating a script to add new users that anyone can run, has to check for the existence of a directory. if the directory does not exist then it has... (12 Replies)
Hi
I am new to expect. Please if any one can help on my issue its really appreciable. here is my issue:
I want expect script for random passwords and random commands generation.
please can anyone help me?
Many Thanks in advance (0 Replies)
Hello All,
I have all of a sudden developed issues with booting up one of my Solaris Servers. Upon a routine reboot, I was faced with the following errors:
Feb 1 07:56:44 sco1-au-tci scsi: WARNING: /pci@1c,600000/scsi@2/sd@0,0 (sd0):
Feb 1 07:56:44 sco1-au-tci Error for Command: read(10)... (9 Replies)
My problem is as follow and i hope you can help:
I currently have this function:
stored_word()
{
number=$RANDOM
let "number %= 21"
case $number in
0 ) echo "energy" ;; 1 ) echo "touch" ;;
2 ) echo "climbing" ;; 3 ) echo "declare" ;;
4 ) echo "marry" ;; 5 ) echo "relax" ... (8 Replies)
Hello Everyone,
I am wondering how to create a Random Password of 8 characters for a user. It has to be run in a script.
Also, The user have to be asked to change his/her password the first time they login.
I tried using genPass but seems like my system doesn't support that command.
For... (1 Reply)
I am a bash shell programmer and I create programs on occasional basis.
Now, I dont want my programs to be run by typing out its name at a command line. I want to make it as user friendly as possible. I want to create icons on the desktop so users can click on it. mind you, I said "desktop... (7 Replies)