LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 09: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, 09:38 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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, 09: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, 09:46 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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 09:47 AM.
 
Old 01-13-2014, 09: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, 09:50 AM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

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


Reply



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 12:10 AM
[SOLVED] count occurrences of numbers between specific values wilelucho Programming 5 09-24-2013 06:31 AM
changing variables to numeric values budgie26 Linux - General 6 01-30-2013 01:11 AM
Bash + Reading values(numbers) from a file and storing them into an array SuchANewb Linux - Newbie 5 11-04-2010 08:11 AM
read values of variables from a table osio Programming 7 01-11-2006 02:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:06 PM.

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
Open Source Consulting | Domain Registration