LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-13-2014, 10:33 AM   #1
rivelino90
LQ Newbie
 
Registered: Jan 2014
Posts: 6

Rep: Reputation: Disabled
how can I give variables values between 2 numbers?


for example I want to give X values between 20 and 50
 
Old 01-13-2014, 10:38 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
A variable cxan at an given time only have one value, unless that variable is made for storing more values, like arrays or lists.
To help you we need to know which programming language and what you actually want to achieve.
Do you need all that values at the same time, do you want to iterate over them, ...?
 
1 members found this post helpful.
Old 01-13-2014, 10:44 AM   #3
rivelino90
LQ Newbie
 
Registered: Jan 2014
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TobiSGD View Post
A variable cxan at an given time only have one value, unless that variable is made for storing more values, like arrays or lists.
To help you we need to know which programming language and what you actually want to achieve.
Do you need all that values at the same time, do you want to iterate over them, ...?
i want to generate random number between 1 and X.and X have values between 20-50.so I thought to do $echo $[RANDOM%X+1] ,but how to give X those values?thank you
 
Old 01-13-2014, 10:46 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
i dont think your question is possible as is because there are an infinite amount of numbers between 20 and 50. maybe you can modify your question to how to check if the value of X is between 20 and 50:
Code:
[schneidz@hyper ~]$ cat rivelino90.c
#include <stdio.h>

main(int argc, char * argv)
{
 float X = 25.5;

 if(20 <= X <= 50)
  printf(" X is between 20 and 50\n");
}
[schneidz@hyper ~]$ ./rivelino90.x
 X is between 20 and 50

Last edited by schneidz; 01-13-2014 at 10:47 AM.
 
Old 01-13-2014, 10:49 AM   #5
rivelino90
LQ Newbie
 
Registered: Jan 2014
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by schneidz View Post
i dont think your question is possible as is because there are an infinite amount of numbers between 20 and 50. maybe you can modify your question to how to check if the value of X is between 20 and 50:
Code:
[schneidz@hyper ~]$ cat rivelino90.c
#include <stdio.h>

main(int argc, char * argv)
{
 float X = 25.5;

 if(20 <= X <= 50)
  printf(" X is between 20 and 50\n");
}
[schneidz@hyper ~]$ ./rivelino90.x
 X is between 20 and 50
i want to generate random number between 1 and X.and X have values between 20-50.so I thought to do $echo $[RANDOM%X+1] ,but how to give X those values?thank you
 
Old 01-13-2014, 10:50 AM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
random whole numbers between 20 and 50:
Code:
expr $RANDOM % 30 + 20
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Why does bash sometimes give me numbers in my prompt, but not all the time? nerdofdarkness Linux - Newbie 5 11-01-2013 01:10 AM
[SOLVED] count occurrences of numbers between specific values wilelucho Programming 5 09-24-2013 07:31 AM
changing variables to numeric values budgie26 Linux - General 6 01-30-2013 02:11 AM
Bash + Reading values(numbers) from a file and storing them into an array SuchANewb Linux - Newbie 5 11-04-2010 09:11 AM
read values of variables from a table osio Programming 7 01-11-2006 03:52 AM


All times are GMT -5. The time now is 06:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration