How can I make a variable a random variable in another variable? The Next CEO of Stack OverflowHow to generate a random alpha-numeric string?How do I call one constructor from another in Java?Fastest way to determine if an integer's square root is an integerHow do I generate random integers within a specific range in Java?Generate random string/characters in JavaScriptGenerating random whole numbers in JavaScript in a specific range?How do I generate a random int number?How do I pick randomly from an array?Generate random number between two numbers in JavaScriptWhy does this code using random strings print “hello world”?
Why do we use the plural of movies in this phrase "We went to the movies last night."?
If/When UK leaves the EU, can a future goverment conduct a referendum to join the EU?
Contours of a clandestine nature
Sending manuscript to multiple publishers
Rotate a column
Are there any unintended negative consequences to allowing PCs to gain multiple levels at once in a short milestone-XP game?
Plot of histogram similar to output from @risk
How to avoid supervisors with prejudiced views?
WOW air has ceased operation, can I get my tickets refunded?
Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis
How do I reset passwords on multiple websites easily?
Why do remote companies require working in the US?
Can I run my washing machine drain line into a condensate pump so it drains better?
How to invert MapIndexed on a ragged structure? How to construct a tree from rules?
Anatomically Correct Strange Women In Ponds Distributing Swords
What is the purpose of the Evocation wizard's Potent Cantrip feature?
Complex fractions
What exact does MIB represent in SNMP? How is it different from OID?
Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?
How to start emacs in "nothing" mode (`fundamental-mode`)
Is it professional to write unrelated content in an almost-empty email?
Are there any limitations on attacking while grappling?
Several mode to write the symbol of a vector
Written every which way
How can I make a variable a random variable in another variable?
The Next CEO of Stack OverflowHow to generate a random alpha-numeric string?How do I call one constructor from another in Java?Fastest way to determine if an integer's square root is an integerHow do I generate random integers within a specific range in Java?Generate random string/characters in JavaScriptGenerating random whole numbers in JavaScript in a specific range?How do I generate a random int number?How do I pick randomly from an array?Generate random number between two numbers in JavaScriptWhy does this code using random strings print “hello world”?
The CL is to get a random Capital Letter & the rest is self explanatory.
String CL = CLetters.get(Randal.nextInt(CLetters.size()));
String L = Letters.get(Randal.nextInt(Letters.size()));
String N = Numbers.get(Randal.nextInt(Numbers.size()));
Then I want another variable CLLN
to be set randomly to either CL
, L
or N
.
I know that I could use an if statement, but then it wouldn't work with the rest of my script or class, I want to use a statement. Something like String CLLN = (CL || L || N);
Is there a way to do so ?
java random
|
show 4 more comments
The CL is to get a random Capital Letter & the rest is self explanatory.
String CL = CLetters.get(Randal.nextInt(CLetters.size()));
String L = Letters.get(Randal.nextInt(Letters.size()));
String N = Numbers.get(Randal.nextInt(Numbers.size()));
Then I want another variable CLLN
to be set randomly to either CL
, L
or N
.
I know that I could use an if statement, but then it wouldn't work with the rest of my script or class, I want to use a statement. Something like String CLLN = (CL || L || N);
Is there a way to do so ?
java random
2
What is the statementString CLLN = (CL || L || N);
supposed to do?
– GBlodgett
Mar 7 at 15:35
String CLLN = (CL || L || N);
won't compile/
– uneq95
Mar 7 at 15:36
My goal is to get CLLN to be CL or L or N.
– JJ's
Mar 7 at 15:36
1
@user11102955 you can't achieve that, using that way. You have to pick a random, then use this random to decide which one to affect to CLLN
– vincrichaud
Mar 7 at 15:37
3
If the desired value is a random choice of CL, L or N, put the three in an array and create a random number to index the array.
– NormR
Mar 7 at 15:39
|
show 4 more comments
The CL is to get a random Capital Letter & the rest is self explanatory.
String CL = CLetters.get(Randal.nextInt(CLetters.size()));
String L = Letters.get(Randal.nextInt(Letters.size()));
String N = Numbers.get(Randal.nextInt(Numbers.size()));
Then I want another variable CLLN
to be set randomly to either CL
, L
or N
.
I know that I could use an if statement, but then it wouldn't work with the rest of my script or class, I want to use a statement. Something like String CLLN = (CL || L || N);
Is there a way to do so ?
java random
The CL is to get a random Capital Letter & the rest is self explanatory.
String CL = CLetters.get(Randal.nextInt(CLetters.size()));
String L = Letters.get(Randal.nextInt(Letters.size()));
String N = Numbers.get(Randal.nextInt(Numbers.size()));
Then I want another variable CLLN
to be set randomly to either CL
, L
or N
.
I know that I could use an if statement, but then it wouldn't work with the rest of my script or class, I want to use a statement. Something like String CLLN = (CL || L || N);
Is there a way to do so ?
java random
java random
edited Mar 7 at 19:09
vincrichaud
1,7961025
1,7961025
asked Mar 7 at 15:34
JJ'sJJ's
33
33
2
What is the statementString CLLN = (CL || L || N);
supposed to do?
– GBlodgett
Mar 7 at 15:35
String CLLN = (CL || L || N);
won't compile/
– uneq95
Mar 7 at 15:36
My goal is to get CLLN to be CL or L or N.
– JJ's
Mar 7 at 15:36
1
@user11102955 you can't achieve that, using that way. You have to pick a random, then use this random to decide which one to affect to CLLN
– vincrichaud
Mar 7 at 15:37
3
If the desired value is a random choice of CL, L or N, put the three in an array and create a random number to index the array.
– NormR
Mar 7 at 15:39
|
show 4 more comments
2
What is the statementString CLLN = (CL || L || N);
supposed to do?
– GBlodgett
Mar 7 at 15:35
String CLLN = (CL || L || N);
won't compile/
– uneq95
Mar 7 at 15:36
My goal is to get CLLN to be CL or L or N.
– JJ's
Mar 7 at 15:36
1
@user11102955 you can't achieve that, using that way. You have to pick a random, then use this random to decide which one to affect to CLLN
– vincrichaud
Mar 7 at 15:37
3
If the desired value is a random choice of CL, L or N, put the three in an array and create a random number to index the array.
– NormR
Mar 7 at 15:39
2
2
What is the statement
String CLLN = (CL || L || N);
supposed to do?– GBlodgett
Mar 7 at 15:35
What is the statement
String CLLN = (CL || L || N);
supposed to do?– GBlodgett
Mar 7 at 15:35
String CLLN = (CL || L || N);
won't compile/– uneq95
Mar 7 at 15:36
String CLLN = (CL || L || N);
won't compile/– uneq95
Mar 7 at 15:36
My goal is to get CLLN to be CL or L or N.
– JJ's
Mar 7 at 15:36
My goal is to get CLLN to be CL or L or N.
– JJ's
Mar 7 at 15:36
1
1
@user11102955 you can't achieve that, using that way. You have to pick a random, then use this random to decide which one to affect to CLLN
– vincrichaud
Mar 7 at 15:37
@user11102955 you can't achieve that, using that way. You have to pick a random, then use this random to decide which one to affect to CLLN
– vincrichaud
Mar 7 at 15:37
3
3
If the desired value is a random choice of CL, L or N, put the three in an array and create a random number to index the array.
– NormR
Mar 7 at 15:39
If the desired value is a random choice of CL, L or N, put the three in an array and create a random number to index the array.
– NormR
Mar 7 at 15:39
|
show 4 more comments
1 Answer
1
active
oldest
votes
I think you want something like this:
String[] values =
CLetters.get(Randal.nextInt(CLetters.size())),
Letters.get(Randal.nextInt(Letters.size())),
Numbers.get(Randal.nextInt(Numbers.size()))
;
String CLLN = values[new Random().nextInt(values.length)];
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047513%2fhow-can-i-make-a-variable-a-random-variable-in-another-variable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think you want something like this:
String[] values =
CLetters.get(Randal.nextInt(CLetters.size())),
Letters.get(Randal.nextInt(Letters.size())),
Numbers.get(Randal.nextInt(Numbers.size()))
;
String CLLN = values[new Random().nextInt(values.length)];
add a comment |
I think you want something like this:
String[] values =
CLetters.get(Randal.nextInt(CLetters.size())),
Letters.get(Randal.nextInt(Letters.size())),
Numbers.get(Randal.nextInt(Numbers.size()))
;
String CLLN = values[new Random().nextInt(values.length)];
add a comment |
I think you want something like this:
String[] values =
CLetters.get(Randal.nextInt(CLetters.size())),
Letters.get(Randal.nextInt(Letters.size())),
Numbers.get(Randal.nextInt(Numbers.size()))
;
String CLLN = values[new Random().nextInt(values.length)];
I think you want something like this:
String[] values =
CLetters.get(Randal.nextInt(CLetters.size())),
Letters.get(Randal.nextInt(Letters.size())),
Numbers.get(Randal.nextInt(Numbers.size()))
;
String CLLN = values[new Random().nextInt(values.length)];
answered Mar 7 at 15:47
ttulkattulka
2,6111627
2,6111627
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047513%2fhow-can-i-make-a-variable-a-random-variable-in-another-variable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
What is the statement
String CLLN = (CL || L || N);
supposed to do?– GBlodgett
Mar 7 at 15:35
String CLLN = (CL || L || N);
won't compile/– uneq95
Mar 7 at 15:36
My goal is to get CLLN to be CL or L or N.
– JJ's
Mar 7 at 15:36
1
@user11102955 you can't achieve that, using that way. You have to pick a random, then use this random to decide which one to affect to CLLN
– vincrichaud
Mar 7 at 15:37
3
If the desired value is a random choice of CL, L or N, put the three in an array and create a random number to index the array.
– NormR
Mar 7 at 15:39