ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello,
I'm still newbie linux user, can someone help me to whrite a script that could generate randomly N numbers that are not repeated within range [1..X]
ok, I'll help you:
pick a language.
learn how to create and use arrays or lists or dictionaries.
read
Code:
man urandom
use that to generate the random number. write it into the array and make sure that array is checked before you write in it again, to avoid duplicates.
let me know how you're doing...
[EDIT]
WAIT A MINUTE...
I just had a look at your homepage, seeing all your certificates, practical experience, dimplomas and all.
THIS CAN'T BE REAL.
something is extremely rotten in the state of LQ.
Are you a fake or just extremely lazy?
You'll be on my ignore list from now on.
[/EDIT]
@mystical dervish: i reconsidered. i won't ignore you.
i'll put you on my buddy list and whenever i find you asking about simple programming tasks again i'll warn everyone!!
I'm still not over it.
this is one especially fascinating entry on his hp:
@mystical dervish: i reconsidered. i won't ignore you.
i'll put you on my buddy list and whenever i find you asking about simple programming tasks again i'll warn everyone!!
Ok, but you have to verify before you decide to adjudge the others,it's very good that you changed to be right. if you don't believe someone that doesnt mean that he is fake. As well I mentioned in my post that Im new user with linux, just 65 days ago with linux, so I'm not lasy dear, one who works with "non repeated numbers" may be engaged in some real technical matter, I think you know that..
if someone wants verify my java cert(for example) he may ask me for that, or for any technical question about my experience
anyway that's good that you returned to th right, but be carful that you can't injure the others by your stones
i went through some of your other threads and it's always the same: you expect people to do your homework. many people around here do that, but they don't have a CV like you do. i'm sorry, s.o. who claims to be excellent at lisp and c won't ask questions like that.
so i'll stick with it: you are either abusing the community because you are too lazy to read for yourself (which is not acceptable from some one with a computer background like yours) or you're a fake.
Well, I'm not going to judge. Besides, these kinds of problems are fun. Here's a solution in MzScheme:
Code:
(define internal (lambda (l max size)
(if (= (length l) size)
l
(let ((rnd (+ (random max) 1)))
(if (member rnd l)
(internal l max size)
(internal (cons rnd l) max size))))))
(define non-repeating-random (lambda (max size)
(if (> size max)
(error "no such list")
(internal '() max size))))
Call it like so:
Code:
Welcome to DrScheme, version 370 [3m].
Language: Pretty Big (includes MrEd and Advanced Student) custom.
> (non-repeating-random 5 3)
(list 1 2 4)
> (non-repeating-random 3 5)
no such list
Last edited by taylor_venable; 06-12-2007 at 11:24 AM.
Hello,
I'm still newbie linux user, can someone help me to whrite a script that could generate randomly N numbers that are not repeated within range [1..X]
This bash script should do what you want:
Code:
bot=1 num=${2:?}
eval "set -- {1..${1:?}"
a=( "$@" )
eval "set -- {1..$num}"
for n
do
r=$(( $RANDOM % ${#a[@]} ))
printf "%d\n" "${a[$r]}"
unset a[$r]
a=( "${a[@]}" )
done
Call it with X and N (in that order) as arguments.
Well, I'm not going to judge. Besides, these kinds of problems are fun. Here's a solution in MzScheme:
Code:
(define internal (lambda (l max size)
(if (= (length l) size)
l
(let ((rnd (+ (random max) 1)))
(if (member rnd l)
(internal l max size)
(internal (cons rnd l) max size))))))
(define non-repeating-random (lambda (max size)
(if (> size max)
(error "no such list")
(internal '() max size))))
Call it like so:
Code:
Welcome to DrScheme, version 370 [3m].
Language: Pretty Big (includes MrEd and Advanced Student) custom.
> (non-repeating-random 5 3)
(list 1 2 4)
> (non-repeating-random 3 5)
no such list
I would like thank you for this lisp code, but now I don't use a list compiler for my project
i went through some of your other threads and it's always the same: you expect people to do your homework. many people around here do that, but they don't have a CV like you do. i'm sorry, s.o. who claims to be excellent at lisp and c won't ask questions like that.
so i'll stick with it: you are either abusing the community because you are too lazy to read for yourself (which is not acceptable from some one with a computer background like yours) or you're a fake.
it's the second time you tried to judge, and abuse me, you should respect the new users to present a good reputation about the community with whome you work. I'm not going to do a homework, I read and learn myself in a way that I see it suitable for me, as you know there are different ways to learn, one of them is by examples, if you see that you are professional don't reply the simple questions, but you have to know that noone is professional in everything.
it's enough for now , but you should apologize for your false judgement
exactly, you expect others to do it for you.
you are obviously a programmer who could easily solve his little problems on his own, but you prefer to have others do it. if people want to do that for you - well, that ain't my business. i for one truly dislike people who abuse others like that. you state that your linux knowledge is not broad enough and i doubt that, but just in case - i can help.
man -k [topic]
man [file|program]
"/" to search
"n" to go to the next hit
that and a internet search engine is all you need.
of course, you don't need it. you simply need a bunch of nice guys to to stuff for you. unfortunately, you seem to get it here.
i certainly won't apologize to you.
guys like you annoy me a lot. you obviously know much much more than i do about programming, but i would at least do the following things b4 i post a question:
1. try on my own
2. ask questions the way it's supposed to be
2a) tell the guy that bothers to read my question what i've tried already
2b) tell him where i'm stuck
as opposed to:
Quote:
I'm still newbie linux user, can someone help me to whrite a script that could generate randomly N numbers that are not repeated within range [1..X]
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.