Generate random sequence of letters of length K from list of letters [duplicate]
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.
python
marked as duplicate by Two-Bit Alchemist, usr2564301, jpp, Prune
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.
add a comment |
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.
python
marked as duplicate by Two-Bit Alchemist, usr2564301, jpp, Prune
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 israndom.choice
. Then just repeat it.
– Michael Butscher
Nov 13 '18 at 17:15
add a comment |
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.
python
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
python
asked Nov 13 '18 at 17:14
m.n.mm.n.m
1
1
marked as duplicate by Two-Bit Alchemist, usr2564301, jpp, Prune
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
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 israndom.choice
. Then just repeat it.
– Michael Butscher
Nov 13 '18 at 17:15
add a comment |
For one random letter of a sequence (e.g. a list) there israndom.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
add a comment |
1 Answer
1
active
oldest
votes
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) ]]
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
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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) ]]
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
add a comment |
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) ]]
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
add a comment |
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) ]]
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) ]]
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
add a comment |
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
add a comment |
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