Generate random sequence of letters of length K from list of letters [duplicate]












-1
















This question already has an answer here:




  • Generate a random letter in Python

    18 answers



  • Generate 'n' unique random numbers within a range [duplicate]

    4 answers




I am trying to write a function that generates a random sequence of letters (letters from a list), and the sequence length is K (K is passed to the function as an argument when function is called). I am stuck, and I don't understand how to generate random sequence of letters.










share|improve this question













marked as duplicate by Two-Bit Alchemist, usr2564301, jpp, Prune python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 '18 at 17:18


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • For one random letter of a sequence (e.g. a list) there is random.choice. Then just repeat it.

    – Michael Butscher
    Nov 13 '18 at 17:15


















-1
















This question already has an answer here:




  • Generate a random letter in Python

    18 answers



  • Generate 'n' unique random numbers within a range [duplicate]

    4 answers




I am trying to write a function that generates a random sequence of letters (letters from a list), and the sequence length is K (K is passed to the function as an argument when function is called). I am stuck, and I don't understand how to generate random sequence of letters.










share|improve this question













marked as duplicate by Two-Bit Alchemist, usr2564301, jpp, Prune python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 '18 at 17:18


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • For one random letter of a sequence (e.g. a list) there is random.choice. Then just repeat it.

    – Michael Butscher
    Nov 13 '18 at 17:15
















-1












-1








-1









This question already has an answer here:




  • Generate a random letter in Python

    18 answers



  • Generate 'n' unique random numbers within a range [duplicate]

    4 answers




I am trying to write a function that generates a random sequence of letters (letters from a list), and the sequence length is K (K is passed to the function as an argument when function is called). I am stuck, and I don't understand how to generate random sequence of letters.










share|improve this question















This question already has an answer here:




  • Generate a random letter in Python

    18 answers



  • Generate 'n' unique random numbers within a range [duplicate]

    4 answers




I am trying to write a function that generates a random sequence of letters (letters from a list), and the sequence length is K (K is passed to the function as an argument when function is called). I am stuck, and I don't understand how to generate random sequence of letters.





This question already has an answer here:




  • Generate a random letter in Python

    18 answers



  • Generate 'n' unique random numbers within a range [duplicate]

    4 answers








python






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 17:14









m.n.mm.n.m

1




1




marked as duplicate by Two-Bit Alchemist, usr2564301, jpp, Prune python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 '18 at 17:18


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Two-Bit Alchemist, usr2564301, jpp, Prune python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 13 '18 at 17:18


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • For one random letter of a sequence (e.g. a list) there is random.choice. Then just repeat it.

    – Michael Butscher
    Nov 13 '18 at 17:15





















  • For one random letter of a sequence (e.g. a list) there is random.choice. Then just repeat it.

    – Michael Butscher
    Nov 13 '18 at 17:15



















For one random letter of a sequence (e.g. a list) there is random.choice. Then just repeat it.

– Michael Butscher
Nov 13 '18 at 17:15







For one random letter of a sequence (e.g. a list) there is random.choice. Then just repeat it.

– Michael Butscher
Nov 13 '18 at 17:15














1 Answer
1






active

oldest

votes


















-1














As mentioned by we can loop the random choice on the given list for k times to get the desired output



Def fn(letters,k):

return [np.random.choice(letters) for _ range(k) ]]





share|improve this answer


























  • Why negative score file for this answer

    – AI_Learning
    Nov 13 '18 at 17:28






  • 1





    Added the explanation

    – AI_Learning
    Nov 13 '18 at 17:50


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









-1














As mentioned by we can loop the random choice on the given list for k times to get the desired output



Def fn(letters,k):

return [np.random.choice(letters) for _ range(k) ]]





share|improve this answer


























  • Why negative score file for this answer

    – AI_Learning
    Nov 13 '18 at 17:28






  • 1





    Added the explanation

    – AI_Learning
    Nov 13 '18 at 17:50
















-1














As mentioned by we can loop the random choice on the given list for k times to get the desired output



Def fn(letters,k):

return [np.random.choice(letters) for _ range(k) ]]





share|improve this answer


























  • Why negative score file for this answer

    – AI_Learning
    Nov 13 '18 at 17:28






  • 1





    Added the explanation

    – AI_Learning
    Nov 13 '18 at 17:50














-1












-1








-1







As mentioned by we can loop the random choice on the given list for k times to get the desired output



Def fn(letters,k):

return [np.random.choice(letters) for _ range(k) ]]





share|improve this answer















As mentioned by we can loop the random choice on the given list for k times to get the desired output



Def fn(letters,k):

return [np.random.choice(letters) for _ range(k) ]]






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 '18 at 17:49

























answered Nov 13 '18 at 17:19









AI_LearningAI_Learning

3,3362933




3,3362933













  • Why negative score file for this answer

    – AI_Learning
    Nov 13 '18 at 17:28






  • 1





    Added the explanation

    – AI_Learning
    Nov 13 '18 at 17:50



















  • Why negative score file for this answer

    – AI_Learning
    Nov 13 '18 at 17:28






  • 1





    Added the explanation

    – AI_Learning
    Nov 13 '18 at 17:50

















Why negative score file for this answer

– AI_Learning
Nov 13 '18 at 17:28





Why negative score file for this answer

– AI_Learning
Nov 13 '18 at 17:28




1




1





Added the explanation

– AI_Learning
Nov 13 '18 at 17:50





Added the explanation

– AI_Learning
Nov 13 '18 at 17:50



Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values