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”?










-1















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 ?










share|improve this question



















  • 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















-1















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 ?










share|improve this question



















  • 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













-1












-1








-1








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 ?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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












  • 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







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












1 Answer
1






active

oldest

votes


















0














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)];





share|improve this answer























    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
    );



    );













    draft saved

    draft discarded


















    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









    0














    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)];





    share|improve this answer



























      0














      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)];





      share|improve this answer

























        0












        0








        0







        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)];





        share|improve this answer













        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)];






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 7 at 15:47









        ttulkattulka

        2,6111627




        2,6111627





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved