To string or not to string












4












$begingroup$


Given an input string, output at random the unique combinations with repetition of the characters in the input string, from length 1 up to the length of the input string, with an equal chance of each one occurring.



Example: given the input abcd (or any combination thereof of the four characters a,b,c,d) , there is an equal chance of outputting:



a b c d aa ab ac ad ba bb bc bd ca cb cc cd da db dc dd aaa aab aac aad aba abb abc abd aca acb acc acd ada adb adc add baa bab bac bad bba bbb bbc bbd bca bcb bcc bcd bda bdb bdc bdd caa cab cac cad cba cbb cbc cbd cca ccb ccc ccd cda cdb cdc cdd daa dab dac dad dba dbb dbc dbd dca dcb dcc dcd dda ddb ddc ddd aaaa aaab aaac aaad aaba aabb aabc aabd aaca aacb aacc aacd aada aadb aadc aadd abaa abab abac abad abba abbb abbc abbd abca abcb abcc abcd abda abdb abdc abdd acaa acab acac acad acba acbb acbc acbd acca accb accc accd acda acdb acdc acdd adaa adab adac adad adba adbb adbc adbd adca adcb adcc adcd adda addb addc addd baaa baab baac baad baba babb babc babd baca bacb bacc bacd bada badb badc badd bbaa bbab bbac bbad bbba bbbb bbbc bbbd bbca bbcb bbcc bbcd bbda bbdb bbdc bbdd bcaa bcab bcac bcad bcba bcbb bcbc bcbd bcca bccb bccc bccd bcda bcdb bcdc bcdd bdaa bdab bdac bdad bdba bdbb bdbc bdbd bdca bdcb bdcc bdcd bdda bddb bddc bddd caaa caab caac caad caba cabb cabc cabd caca cacb cacc cacd cada cadb cadc cadd cbaa cbab cbac cbad cbba cbbb cbbc cbbd cbca cbcb cbcc cbcd cbda cbdb cbdc cbdd ccaa ccab ccac ccad ccba ccbb ccbc ccbd ccca cccb cccc cccd ccda ccdb ccdc ccdd cdaa cdab cdac cdad cdba cdbb cdbc cdbd cdca cdcb cdcc cdcd cdda cddb cddc cddd daaa daab daac daad daba dabb dabc dabd daca dacb dacc dacd dada dadb dadc dadd dbaa dbab dbac dbad dbba dbbb dbbc dbbd dbca dbcb dbcc dbcd dbda dbdb dbdc dbdd dcaa dcab dcac dcad dcba dcbb dcbc dcbd dcca dccb dccc dccd dcda dcdb dcdc dcdd ddaa ddab ddac ddad ddba ddbb ddbc ddbd ddca ddcb ddcc ddcd ddda dddb dddc dddd


Example: given the input efgh (or any combination thereof of the four characters e,f,g,h), there is an equal chance of outputting:



e f g h ee ef eg eh fe ff fg fh ge gf gg gh he hf hg hh eee eef eeg eeh efe eff efg efh ege egf egg egh ehe ehf ehg ehh fee fef feg feh ffe fff ffg ffh fge fgf fgg fgh fhe fhf fhg fhh gee gef geg geh gfe gff gfg gfh gge ggf ggg ggh ghe ghf ghg ghh hee hef heg heh hfe hff hfg hfh hge hgf hgg hgh hhe hhf hhg hhh eeee eeef eeeg eeeh eefe eeff eefg eefh eege eegf eegg eegh eehe eehf eehg eehh efee efef efeg efeh effe efff effg effh efge efgf efgg efgh efhe efhf efhg efhh egee egef egeg egeh egfe egff egfg egfh egge eggf eggg eggh eghe eghf eghg eghh ehee ehef eheg eheh ehfe ehff ehfg ehfh ehge ehgf ehgg ehgh ehhe ehhf ehhg ehhh feee feef feeg feeh fefe feff fefg fefh fege fegf fegg fegh fehe fehf fehg fehh ffee ffef ffeg ffeh fffe ffff fffg fffh ffge ffgf ffgg ffgh ffhe ffhf ffhg ffhh fgee fgef fgeg fgeh fgfe fgff fgfg fgfh fgge fggf fggg fggh fghe fghf fghg fghh fhee fhef fheg fheh fhfe fhff fhfg fhfh fhge fhgf fhgg fhgh fhhe fhhf fhhg fhhh geee geef geeg geeh gefe geff gefg gefh gege gegf gegg gegh gehe gehf gehg gehh gfee gfef gfeg gfeh gffe gfff gffg gffh gfge gfgf gfgg gfgh gfhe gfhf gfhg gfhh ggee ggef ggeg ggeh ggfe ggff ggfg ggfh ggge gggf gggg gggh gghe gghf gghg gghh ghee ghef gheg gheh ghfe ghff ghfg ghfh ghge ghgf ghgg ghgh ghhe ghhf ghhg ghhh heee heef heeg heeh hefe heff hefg hefh hege hegf hegg hegh hehe hehf hehg hehh hfee hfef hfeg hfeh hffe hfff hffg hffh hfge hfgf hfgg hfgh hfhe hfhf hfhg hfhh hgee hgef hgeg hgeh hgfe hgff hgfg hgfh hgge hggf hggg hggh hghe hghf hghg hghh hhee hhef hheg hheh hhfe hhff hhfg hhfh hhge hhgf hhgg hhgh hhhe hhhf hhhg hhhh


Example: given the input ijkl (or any combination thereof of the four characters i,j,k,l), there is an equal chance of outputting:



i j k l ii ij ik il ji jj jk jl ki kj kk kl li lj lk ll iii iij iik iil iji ijj ijk ijl iki ikj ikk ikl ili ilj ilk ill jii jij jik jil jji jjj jjk jjl jki jkj jkk jkl jli jlj jlk jll kii kij kik kil kji kjj kjk kjl kki kkj kkk kkl kli klj klk kll lii lij lik lil lji ljj ljk ljl lki lkj lkk lkl lli llj llk lll iiii iiij iiik iiil iiji iijj iijk iijl iiki iikj iikk iikl iili iilj iilk iill ijii ijij ijik ijil ijji ijjj ijjk ijjl ijki ijkj ijkk ijkl ijli ijlj ijlk ijll ikii ikij ikik ikil ikji ikjj ikjk ikjl ikki ikkj ikkk ikkl ikli iklj iklk ikll ilii ilij ilik ilil ilji iljj iljk iljl ilki ilkj ilkk ilkl illi illj illk illl jiii jiij jiik jiil jiji jijj jijk jijl jiki jikj jikk jikl jili jilj jilk jill jjii jjij jjik jjil jjji jjjj jjjk jjjl jjki jjkj jjkk jjkl jjli jjlj jjlk jjll jkii jkij jkik jkil jkji jkjj jkjk jkjl jkki jkkj jkkk jkkl jkli jklj jklk jkll jlii jlij jlik jlil jlji jljj jljk jljl jlki jlkj jlkk jlkl jlli jllj jllk jlll kiii kiij kiik kiil kiji kijj kijk kijl kiki kikj kikk kikl kili kilj kilk kill kjii kjij kjik kjil kjji kjjj kjjk kjjl kjki kjkj kjkk kjkl kjli kjlj kjlk kjll kkii kkij kkik kkil kkji kkjj kkjk kkjl kkki kkkj kkkk kkkl kkli kklj kklk kkll klii klij klik klil klji kljj kljk kljl klki klkj klkk klkl klli kllj kllk klll liii liij liik liil liji lijj lijk lijl liki likj likk likl lili lilj lilk lill ljii ljij ljik ljil ljji ljjj ljjk ljjl ljki ljkj ljkk ljkl ljli ljlj ljlk ljll lkii lkij lkik lkil lkji lkjj lkjk lkjl lkki lkkj lkkk lkkl lkli lklj lklk lkll llii llij llik llil llji lljj lljk lljl llki llkj llkk llkl llli lllj lllk llll


Every individual character within the string has equal probability as well.



For example, given an output of aaab, this does not mean that a has more probability of occuring, rather a and b have equal probability of occurence.



Another example, given an output of aaabeeeee, this does not mean that e has the highest probability of occuring, rather a and b and e all have equal probability of occurence.



The input is guranteed to have at least two distinct characters.










share|improve this question









New contributor




Flog Edoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$












  • $begingroup$
    Comments are not for extended discussion; this conversation has been moved to chat.
    $endgroup$
    – DJMcMayhem
    14 hours ago










  • $begingroup$
    @EmbodimentofIgnorance Thanks, fixed.
    $endgroup$
    – Flog Edoc
    12 hours ago










  • $begingroup$
    Is the input guaranteed to have at least two distinct characters?
    $endgroup$
    – Neil
    11 hours ago










  • $begingroup$
    @Neil Yes, indeed.
    $endgroup$
    – Flog Edoc
    11 hours ago










  • $begingroup$
    A terminology issue (because terminology is important here): 'aaa' is not a subset/subsection/substring/subsequence of any permutation of 'abcd'. Every permutation of 'abcd' has exactly 1 'a' in it.
    $endgroup$
    – Chas Brown
    10 hours ago


















4












$begingroup$


Given an input string, output at random the unique combinations with repetition of the characters in the input string, from length 1 up to the length of the input string, with an equal chance of each one occurring.



Example: given the input abcd (or any combination thereof of the four characters a,b,c,d) , there is an equal chance of outputting:



a b c d aa ab ac ad ba bb bc bd ca cb cc cd da db dc dd aaa aab aac aad aba abb abc abd aca acb acc acd ada adb adc add baa bab bac bad bba bbb bbc bbd bca bcb bcc bcd bda bdb bdc bdd caa cab cac cad cba cbb cbc cbd cca ccb ccc ccd cda cdb cdc cdd daa dab dac dad dba dbb dbc dbd dca dcb dcc dcd dda ddb ddc ddd aaaa aaab aaac aaad aaba aabb aabc aabd aaca aacb aacc aacd aada aadb aadc aadd abaa abab abac abad abba abbb abbc abbd abca abcb abcc abcd abda abdb abdc abdd acaa acab acac acad acba acbb acbc acbd acca accb accc accd acda acdb acdc acdd adaa adab adac adad adba adbb adbc adbd adca adcb adcc adcd adda addb addc addd baaa baab baac baad baba babb babc babd baca bacb bacc bacd bada badb badc badd bbaa bbab bbac bbad bbba bbbb bbbc bbbd bbca bbcb bbcc bbcd bbda bbdb bbdc bbdd bcaa bcab bcac bcad bcba bcbb bcbc bcbd bcca bccb bccc bccd bcda bcdb bcdc bcdd bdaa bdab bdac bdad bdba bdbb bdbc bdbd bdca bdcb bdcc bdcd bdda bddb bddc bddd caaa caab caac caad caba cabb cabc cabd caca cacb cacc cacd cada cadb cadc cadd cbaa cbab cbac cbad cbba cbbb cbbc cbbd cbca cbcb cbcc cbcd cbda cbdb cbdc cbdd ccaa ccab ccac ccad ccba ccbb ccbc ccbd ccca cccb cccc cccd ccda ccdb ccdc ccdd cdaa cdab cdac cdad cdba cdbb cdbc cdbd cdca cdcb cdcc cdcd cdda cddb cddc cddd daaa daab daac daad daba dabb dabc dabd daca dacb dacc dacd dada dadb dadc dadd dbaa dbab dbac dbad dbba dbbb dbbc dbbd dbca dbcb dbcc dbcd dbda dbdb dbdc dbdd dcaa dcab dcac dcad dcba dcbb dcbc dcbd dcca dccb dccc dccd dcda dcdb dcdc dcdd ddaa ddab ddac ddad ddba ddbb ddbc ddbd ddca ddcb ddcc ddcd ddda dddb dddc dddd


Example: given the input efgh (or any combination thereof of the four characters e,f,g,h), there is an equal chance of outputting:



e f g h ee ef eg eh fe ff fg fh ge gf gg gh he hf hg hh eee eef eeg eeh efe eff efg efh ege egf egg egh ehe ehf ehg ehh fee fef feg feh ffe fff ffg ffh fge fgf fgg fgh fhe fhf fhg fhh gee gef geg geh gfe gff gfg gfh gge ggf ggg ggh ghe ghf ghg ghh hee hef heg heh hfe hff hfg hfh hge hgf hgg hgh hhe hhf hhg hhh eeee eeef eeeg eeeh eefe eeff eefg eefh eege eegf eegg eegh eehe eehf eehg eehh efee efef efeg efeh effe efff effg effh efge efgf efgg efgh efhe efhf efhg efhh egee egef egeg egeh egfe egff egfg egfh egge eggf eggg eggh eghe eghf eghg eghh ehee ehef eheg eheh ehfe ehff ehfg ehfh ehge ehgf ehgg ehgh ehhe ehhf ehhg ehhh feee feef feeg feeh fefe feff fefg fefh fege fegf fegg fegh fehe fehf fehg fehh ffee ffef ffeg ffeh fffe ffff fffg fffh ffge ffgf ffgg ffgh ffhe ffhf ffhg ffhh fgee fgef fgeg fgeh fgfe fgff fgfg fgfh fgge fggf fggg fggh fghe fghf fghg fghh fhee fhef fheg fheh fhfe fhff fhfg fhfh fhge fhgf fhgg fhgh fhhe fhhf fhhg fhhh geee geef geeg geeh gefe geff gefg gefh gege gegf gegg gegh gehe gehf gehg gehh gfee gfef gfeg gfeh gffe gfff gffg gffh gfge gfgf gfgg gfgh gfhe gfhf gfhg gfhh ggee ggef ggeg ggeh ggfe ggff ggfg ggfh ggge gggf gggg gggh gghe gghf gghg gghh ghee ghef gheg gheh ghfe ghff ghfg ghfh ghge ghgf ghgg ghgh ghhe ghhf ghhg ghhh heee heef heeg heeh hefe heff hefg hefh hege hegf hegg hegh hehe hehf hehg hehh hfee hfef hfeg hfeh hffe hfff hffg hffh hfge hfgf hfgg hfgh hfhe hfhf hfhg hfhh hgee hgef hgeg hgeh hgfe hgff hgfg hgfh hgge hggf hggg hggh hghe hghf hghg hghh hhee hhef hheg hheh hhfe hhff hhfg hhfh hhge hhgf hhgg hhgh hhhe hhhf hhhg hhhh


Example: given the input ijkl (or any combination thereof of the four characters i,j,k,l), there is an equal chance of outputting:



i j k l ii ij ik il ji jj jk jl ki kj kk kl li lj lk ll iii iij iik iil iji ijj ijk ijl iki ikj ikk ikl ili ilj ilk ill jii jij jik jil jji jjj jjk jjl jki jkj jkk jkl jli jlj jlk jll kii kij kik kil kji kjj kjk kjl kki kkj kkk kkl kli klj klk kll lii lij lik lil lji ljj ljk ljl lki lkj lkk lkl lli llj llk lll iiii iiij iiik iiil iiji iijj iijk iijl iiki iikj iikk iikl iili iilj iilk iill ijii ijij ijik ijil ijji ijjj ijjk ijjl ijki ijkj ijkk ijkl ijli ijlj ijlk ijll ikii ikij ikik ikil ikji ikjj ikjk ikjl ikki ikkj ikkk ikkl ikli iklj iklk ikll ilii ilij ilik ilil ilji iljj iljk iljl ilki ilkj ilkk ilkl illi illj illk illl jiii jiij jiik jiil jiji jijj jijk jijl jiki jikj jikk jikl jili jilj jilk jill jjii jjij jjik jjil jjji jjjj jjjk jjjl jjki jjkj jjkk jjkl jjli jjlj jjlk jjll jkii jkij jkik jkil jkji jkjj jkjk jkjl jkki jkkj jkkk jkkl jkli jklj jklk jkll jlii jlij jlik jlil jlji jljj jljk jljl jlki jlkj jlkk jlkl jlli jllj jllk jlll kiii kiij kiik kiil kiji kijj kijk kijl kiki kikj kikk kikl kili kilj kilk kill kjii kjij kjik kjil kjji kjjj kjjk kjjl kjki kjkj kjkk kjkl kjli kjlj kjlk kjll kkii kkij kkik kkil kkji kkjj kkjk kkjl kkki kkkj kkkk kkkl kkli kklj kklk kkll klii klij klik klil klji kljj kljk kljl klki klkj klkk klkl klli kllj kllk klll liii liij liik liil liji lijj lijk lijl liki likj likk likl lili lilj lilk lill ljii ljij ljik ljil ljji ljjj ljjk ljjl ljki ljkj ljkk ljkl ljli ljlj ljlk ljll lkii lkij lkik lkil lkji lkjj lkjk lkjl lkki lkkj lkkk lkkl lkli lklj lklk lkll llii llij llik llil llji lljj lljk lljl llki llkj llkk llkl llli lllj lllk llll


Every individual character within the string has equal probability as well.



For example, given an output of aaab, this does not mean that a has more probability of occuring, rather a and b have equal probability of occurence.



Another example, given an output of aaabeeeee, this does not mean that e has the highest probability of occuring, rather a and b and e all have equal probability of occurence.



The input is guranteed to have at least two distinct characters.










share|improve this question









New contributor




Flog Edoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$












  • $begingroup$
    Comments are not for extended discussion; this conversation has been moved to chat.
    $endgroup$
    – DJMcMayhem
    14 hours ago










  • $begingroup$
    @EmbodimentofIgnorance Thanks, fixed.
    $endgroup$
    – Flog Edoc
    12 hours ago










  • $begingroup$
    Is the input guaranteed to have at least two distinct characters?
    $endgroup$
    – Neil
    11 hours ago










  • $begingroup$
    @Neil Yes, indeed.
    $endgroup$
    – Flog Edoc
    11 hours ago










  • $begingroup$
    A terminology issue (because terminology is important here): 'aaa' is not a subset/subsection/substring/subsequence of any permutation of 'abcd'. Every permutation of 'abcd' has exactly 1 'a' in it.
    $endgroup$
    – Chas Brown
    10 hours ago
















4












4








4





$begingroup$


Given an input string, output at random the unique combinations with repetition of the characters in the input string, from length 1 up to the length of the input string, with an equal chance of each one occurring.



Example: given the input abcd (or any combination thereof of the four characters a,b,c,d) , there is an equal chance of outputting:



a b c d aa ab ac ad ba bb bc bd ca cb cc cd da db dc dd aaa aab aac aad aba abb abc abd aca acb acc acd ada adb adc add baa bab bac bad bba bbb bbc bbd bca bcb bcc bcd bda bdb bdc bdd caa cab cac cad cba cbb cbc cbd cca ccb ccc ccd cda cdb cdc cdd daa dab dac dad dba dbb dbc dbd dca dcb dcc dcd dda ddb ddc ddd aaaa aaab aaac aaad aaba aabb aabc aabd aaca aacb aacc aacd aada aadb aadc aadd abaa abab abac abad abba abbb abbc abbd abca abcb abcc abcd abda abdb abdc abdd acaa acab acac acad acba acbb acbc acbd acca accb accc accd acda acdb acdc acdd adaa adab adac adad adba adbb adbc adbd adca adcb adcc adcd adda addb addc addd baaa baab baac baad baba babb babc babd baca bacb bacc bacd bada badb badc badd bbaa bbab bbac bbad bbba bbbb bbbc bbbd bbca bbcb bbcc bbcd bbda bbdb bbdc bbdd bcaa bcab bcac bcad bcba bcbb bcbc bcbd bcca bccb bccc bccd bcda bcdb bcdc bcdd bdaa bdab bdac bdad bdba bdbb bdbc bdbd bdca bdcb bdcc bdcd bdda bddb bddc bddd caaa caab caac caad caba cabb cabc cabd caca cacb cacc cacd cada cadb cadc cadd cbaa cbab cbac cbad cbba cbbb cbbc cbbd cbca cbcb cbcc cbcd cbda cbdb cbdc cbdd ccaa ccab ccac ccad ccba ccbb ccbc ccbd ccca cccb cccc cccd ccda ccdb ccdc ccdd cdaa cdab cdac cdad cdba cdbb cdbc cdbd cdca cdcb cdcc cdcd cdda cddb cddc cddd daaa daab daac daad daba dabb dabc dabd daca dacb dacc dacd dada dadb dadc dadd dbaa dbab dbac dbad dbba dbbb dbbc dbbd dbca dbcb dbcc dbcd dbda dbdb dbdc dbdd dcaa dcab dcac dcad dcba dcbb dcbc dcbd dcca dccb dccc dccd dcda dcdb dcdc dcdd ddaa ddab ddac ddad ddba ddbb ddbc ddbd ddca ddcb ddcc ddcd ddda dddb dddc dddd


Example: given the input efgh (or any combination thereof of the four characters e,f,g,h), there is an equal chance of outputting:



e f g h ee ef eg eh fe ff fg fh ge gf gg gh he hf hg hh eee eef eeg eeh efe eff efg efh ege egf egg egh ehe ehf ehg ehh fee fef feg feh ffe fff ffg ffh fge fgf fgg fgh fhe fhf fhg fhh gee gef geg geh gfe gff gfg gfh gge ggf ggg ggh ghe ghf ghg ghh hee hef heg heh hfe hff hfg hfh hge hgf hgg hgh hhe hhf hhg hhh eeee eeef eeeg eeeh eefe eeff eefg eefh eege eegf eegg eegh eehe eehf eehg eehh efee efef efeg efeh effe efff effg effh efge efgf efgg efgh efhe efhf efhg efhh egee egef egeg egeh egfe egff egfg egfh egge eggf eggg eggh eghe eghf eghg eghh ehee ehef eheg eheh ehfe ehff ehfg ehfh ehge ehgf ehgg ehgh ehhe ehhf ehhg ehhh feee feef feeg feeh fefe feff fefg fefh fege fegf fegg fegh fehe fehf fehg fehh ffee ffef ffeg ffeh fffe ffff fffg fffh ffge ffgf ffgg ffgh ffhe ffhf ffhg ffhh fgee fgef fgeg fgeh fgfe fgff fgfg fgfh fgge fggf fggg fggh fghe fghf fghg fghh fhee fhef fheg fheh fhfe fhff fhfg fhfh fhge fhgf fhgg fhgh fhhe fhhf fhhg fhhh geee geef geeg geeh gefe geff gefg gefh gege gegf gegg gegh gehe gehf gehg gehh gfee gfef gfeg gfeh gffe gfff gffg gffh gfge gfgf gfgg gfgh gfhe gfhf gfhg gfhh ggee ggef ggeg ggeh ggfe ggff ggfg ggfh ggge gggf gggg gggh gghe gghf gghg gghh ghee ghef gheg gheh ghfe ghff ghfg ghfh ghge ghgf ghgg ghgh ghhe ghhf ghhg ghhh heee heef heeg heeh hefe heff hefg hefh hege hegf hegg hegh hehe hehf hehg hehh hfee hfef hfeg hfeh hffe hfff hffg hffh hfge hfgf hfgg hfgh hfhe hfhf hfhg hfhh hgee hgef hgeg hgeh hgfe hgff hgfg hgfh hgge hggf hggg hggh hghe hghf hghg hghh hhee hhef hheg hheh hhfe hhff hhfg hhfh hhge hhgf hhgg hhgh hhhe hhhf hhhg hhhh


Example: given the input ijkl (or any combination thereof of the four characters i,j,k,l), there is an equal chance of outputting:



i j k l ii ij ik il ji jj jk jl ki kj kk kl li lj lk ll iii iij iik iil iji ijj ijk ijl iki ikj ikk ikl ili ilj ilk ill jii jij jik jil jji jjj jjk jjl jki jkj jkk jkl jli jlj jlk jll kii kij kik kil kji kjj kjk kjl kki kkj kkk kkl kli klj klk kll lii lij lik lil lji ljj ljk ljl lki lkj lkk lkl lli llj llk lll iiii iiij iiik iiil iiji iijj iijk iijl iiki iikj iikk iikl iili iilj iilk iill ijii ijij ijik ijil ijji ijjj ijjk ijjl ijki ijkj ijkk ijkl ijli ijlj ijlk ijll ikii ikij ikik ikil ikji ikjj ikjk ikjl ikki ikkj ikkk ikkl ikli iklj iklk ikll ilii ilij ilik ilil ilji iljj iljk iljl ilki ilkj ilkk ilkl illi illj illk illl jiii jiij jiik jiil jiji jijj jijk jijl jiki jikj jikk jikl jili jilj jilk jill jjii jjij jjik jjil jjji jjjj jjjk jjjl jjki jjkj jjkk jjkl jjli jjlj jjlk jjll jkii jkij jkik jkil jkji jkjj jkjk jkjl jkki jkkj jkkk jkkl jkli jklj jklk jkll jlii jlij jlik jlil jlji jljj jljk jljl jlki jlkj jlkk jlkl jlli jllj jllk jlll kiii kiij kiik kiil kiji kijj kijk kijl kiki kikj kikk kikl kili kilj kilk kill kjii kjij kjik kjil kjji kjjj kjjk kjjl kjki kjkj kjkk kjkl kjli kjlj kjlk kjll kkii kkij kkik kkil kkji kkjj kkjk kkjl kkki kkkj kkkk kkkl kkli kklj kklk kkll klii klij klik klil klji kljj kljk kljl klki klkj klkk klkl klli kllj kllk klll liii liij liik liil liji lijj lijk lijl liki likj likk likl lili lilj lilk lill ljii ljij ljik ljil ljji ljjj ljjk ljjl ljki ljkj ljkk ljkl ljli ljlj ljlk ljll lkii lkij lkik lkil lkji lkjj lkjk lkjl lkki lkkj lkkk lkkl lkli lklj lklk lkll llii llij llik llil llji lljj lljk lljl llki llkj llkk llkl llli lllj lllk llll


Every individual character within the string has equal probability as well.



For example, given an output of aaab, this does not mean that a has more probability of occuring, rather a and b have equal probability of occurence.



Another example, given an output of aaabeeeee, this does not mean that e has the highest probability of occuring, rather a and b and e all have equal probability of occurence.



The input is guranteed to have at least two distinct characters.










share|improve this question









New contributor




Flog Edoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




Given an input string, output at random the unique combinations with repetition of the characters in the input string, from length 1 up to the length of the input string, with an equal chance of each one occurring.



Example: given the input abcd (or any combination thereof of the four characters a,b,c,d) , there is an equal chance of outputting:



a b c d aa ab ac ad ba bb bc bd ca cb cc cd da db dc dd aaa aab aac aad aba abb abc abd aca acb acc acd ada adb adc add baa bab bac bad bba bbb bbc bbd bca bcb bcc bcd bda bdb bdc bdd caa cab cac cad cba cbb cbc cbd cca ccb ccc ccd cda cdb cdc cdd daa dab dac dad dba dbb dbc dbd dca dcb dcc dcd dda ddb ddc ddd aaaa aaab aaac aaad aaba aabb aabc aabd aaca aacb aacc aacd aada aadb aadc aadd abaa abab abac abad abba abbb abbc abbd abca abcb abcc abcd abda abdb abdc abdd acaa acab acac acad acba acbb acbc acbd acca accb accc accd acda acdb acdc acdd adaa adab adac adad adba adbb adbc adbd adca adcb adcc adcd adda addb addc addd baaa baab baac baad baba babb babc babd baca bacb bacc bacd bada badb badc badd bbaa bbab bbac bbad bbba bbbb bbbc bbbd bbca bbcb bbcc bbcd bbda bbdb bbdc bbdd bcaa bcab bcac bcad bcba bcbb bcbc bcbd bcca bccb bccc bccd bcda bcdb bcdc bcdd bdaa bdab bdac bdad bdba bdbb bdbc bdbd bdca bdcb bdcc bdcd bdda bddb bddc bddd caaa caab caac caad caba cabb cabc cabd caca cacb cacc cacd cada cadb cadc cadd cbaa cbab cbac cbad cbba cbbb cbbc cbbd cbca cbcb cbcc cbcd cbda cbdb cbdc cbdd ccaa ccab ccac ccad ccba ccbb ccbc ccbd ccca cccb cccc cccd ccda ccdb ccdc ccdd cdaa cdab cdac cdad cdba cdbb cdbc cdbd cdca cdcb cdcc cdcd cdda cddb cddc cddd daaa daab daac daad daba dabb dabc dabd daca dacb dacc dacd dada dadb dadc dadd dbaa dbab dbac dbad dbba dbbb dbbc dbbd dbca dbcb dbcc dbcd dbda dbdb dbdc dbdd dcaa dcab dcac dcad dcba dcbb dcbc dcbd dcca dccb dccc dccd dcda dcdb dcdc dcdd ddaa ddab ddac ddad ddba ddbb ddbc ddbd ddca ddcb ddcc ddcd ddda dddb dddc dddd


Example: given the input efgh (or any combination thereof of the four characters e,f,g,h), there is an equal chance of outputting:



e f g h ee ef eg eh fe ff fg fh ge gf gg gh he hf hg hh eee eef eeg eeh efe eff efg efh ege egf egg egh ehe ehf ehg ehh fee fef feg feh ffe fff ffg ffh fge fgf fgg fgh fhe fhf fhg fhh gee gef geg geh gfe gff gfg gfh gge ggf ggg ggh ghe ghf ghg ghh hee hef heg heh hfe hff hfg hfh hge hgf hgg hgh hhe hhf hhg hhh eeee eeef eeeg eeeh eefe eeff eefg eefh eege eegf eegg eegh eehe eehf eehg eehh efee efef efeg efeh effe efff effg effh efge efgf efgg efgh efhe efhf efhg efhh egee egef egeg egeh egfe egff egfg egfh egge eggf eggg eggh eghe eghf eghg eghh ehee ehef eheg eheh ehfe ehff ehfg ehfh ehge ehgf ehgg ehgh ehhe ehhf ehhg ehhh feee feef feeg feeh fefe feff fefg fefh fege fegf fegg fegh fehe fehf fehg fehh ffee ffef ffeg ffeh fffe ffff fffg fffh ffge ffgf ffgg ffgh ffhe ffhf ffhg ffhh fgee fgef fgeg fgeh fgfe fgff fgfg fgfh fgge fggf fggg fggh fghe fghf fghg fghh fhee fhef fheg fheh fhfe fhff fhfg fhfh fhge fhgf fhgg fhgh fhhe fhhf fhhg fhhh geee geef geeg geeh gefe geff gefg gefh gege gegf gegg gegh gehe gehf gehg gehh gfee gfef gfeg gfeh gffe gfff gffg gffh gfge gfgf gfgg gfgh gfhe gfhf gfhg gfhh ggee ggef ggeg ggeh ggfe ggff ggfg ggfh ggge gggf gggg gggh gghe gghf gghg gghh ghee ghef gheg gheh ghfe ghff ghfg ghfh ghge ghgf ghgg ghgh ghhe ghhf ghhg ghhh heee heef heeg heeh hefe heff hefg hefh hege hegf hegg hegh hehe hehf hehg hehh hfee hfef hfeg hfeh hffe hfff hffg hffh hfge hfgf hfgg hfgh hfhe hfhf hfhg hfhh hgee hgef hgeg hgeh hgfe hgff hgfg hgfh hgge hggf hggg hggh hghe hghf hghg hghh hhee hhef hheg hheh hhfe hhff hhfg hhfh hhge hhgf hhgg hhgh hhhe hhhf hhhg hhhh


Example: given the input ijkl (or any combination thereof of the four characters i,j,k,l), there is an equal chance of outputting:



i j k l ii ij ik il ji jj jk jl ki kj kk kl li lj lk ll iii iij iik iil iji ijj ijk ijl iki ikj ikk ikl ili ilj ilk ill jii jij jik jil jji jjj jjk jjl jki jkj jkk jkl jli jlj jlk jll kii kij kik kil kji kjj kjk kjl kki kkj kkk kkl kli klj klk kll lii lij lik lil lji ljj ljk ljl lki lkj lkk lkl lli llj llk lll iiii iiij iiik iiil iiji iijj iijk iijl iiki iikj iikk iikl iili iilj iilk iill ijii ijij ijik ijil ijji ijjj ijjk ijjl ijki ijkj ijkk ijkl ijli ijlj ijlk ijll ikii ikij ikik ikil ikji ikjj ikjk ikjl ikki ikkj ikkk ikkl ikli iklj iklk ikll ilii ilij ilik ilil ilji iljj iljk iljl ilki ilkj ilkk ilkl illi illj illk illl jiii jiij jiik jiil jiji jijj jijk jijl jiki jikj jikk jikl jili jilj jilk jill jjii jjij jjik jjil jjji jjjj jjjk jjjl jjki jjkj jjkk jjkl jjli jjlj jjlk jjll jkii jkij jkik jkil jkji jkjj jkjk jkjl jkki jkkj jkkk jkkl jkli jklj jklk jkll jlii jlij jlik jlil jlji jljj jljk jljl jlki jlkj jlkk jlkl jlli jllj jllk jlll kiii kiij kiik kiil kiji kijj kijk kijl kiki kikj kikk kikl kili kilj kilk kill kjii kjij kjik kjil kjji kjjj kjjk kjjl kjki kjkj kjkk kjkl kjli kjlj kjlk kjll kkii kkij kkik kkil kkji kkjj kkjk kkjl kkki kkkj kkkk kkkl kkli kklj kklk kkll klii klij klik klil klji kljj kljk kljl klki klkj klkk klkl klli kllj kllk klll liii liij liik liil liji lijj lijk lijl liki likj likk likl lili lilj lilk lill ljii ljij ljik ljil ljji ljjj ljjk ljjl ljki ljkj ljkk ljkl ljli ljlj ljlk ljll lkii lkij lkik lkil lkji lkjj lkjk lkjl lkki lkkj lkkk lkkl lkli lklj lklk lkll llii llij llik llil llji lljj lljk lljl llki llkj llkk llkl llli lllj lllk llll


Every individual character within the string has equal probability as well.



For example, given an output of aaab, this does not mean that a has more probability of occuring, rather a and b have equal probability of occurence.



Another example, given an output of aaabeeeee, this does not mean that e has the highest probability of occuring, rather a and b and e all have equal probability of occurence.



The input is guranteed to have at least two distinct characters.







code-golf string random






share|improve this question









New contributor




Flog Edoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Flog Edoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 9 hours ago







Flog Edoc













New contributor




Flog Edoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 18 hours ago









Flog EdocFlog Edoc

263




263




New contributor




Flog Edoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Flog Edoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Flog Edoc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • $begingroup$
    Comments are not for extended discussion; this conversation has been moved to chat.
    $endgroup$
    – DJMcMayhem
    14 hours ago










  • $begingroup$
    @EmbodimentofIgnorance Thanks, fixed.
    $endgroup$
    – Flog Edoc
    12 hours ago










  • $begingroup$
    Is the input guaranteed to have at least two distinct characters?
    $endgroup$
    – Neil
    11 hours ago










  • $begingroup$
    @Neil Yes, indeed.
    $endgroup$
    – Flog Edoc
    11 hours ago










  • $begingroup$
    A terminology issue (because terminology is important here): 'aaa' is not a subset/subsection/substring/subsequence of any permutation of 'abcd'. Every permutation of 'abcd' has exactly 1 'a' in it.
    $endgroup$
    – Chas Brown
    10 hours ago




















  • $begingroup$
    Comments are not for extended discussion; this conversation has been moved to chat.
    $endgroup$
    – DJMcMayhem
    14 hours ago










  • $begingroup$
    @EmbodimentofIgnorance Thanks, fixed.
    $endgroup$
    – Flog Edoc
    12 hours ago










  • $begingroup$
    Is the input guaranteed to have at least two distinct characters?
    $endgroup$
    – Neil
    11 hours ago










  • $begingroup$
    @Neil Yes, indeed.
    $endgroup$
    – Flog Edoc
    11 hours ago










  • $begingroup$
    A terminology issue (because terminology is important here): 'aaa' is not a subset/subsection/substring/subsequence of any permutation of 'abcd'. Every permutation of 'abcd' has exactly 1 'a' in it.
    $endgroup$
    – Chas Brown
    10 hours ago


















$begingroup$
Comments are not for extended discussion; this conversation has been moved to chat.
$endgroup$
– DJMcMayhem
14 hours ago




$begingroup$
Comments are not for extended discussion; this conversation has been moved to chat.
$endgroup$
– DJMcMayhem
14 hours ago












$begingroup$
@EmbodimentofIgnorance Thanks, fixed.
$endgroup$
– Flog Edoc
12 hours ago




$begingroup$
@EmbodimentofIgnorance Thanks, fixed.
$endgroup$
– Flog Edoc
12 hours ago












$begingroup$
Is the input guaranteed to have at least two distinct characters?
$endgroup$
– Neil
11 hours ago




$begingroup$
Is the input guaranteed to have at least two distinct characters?
$endgroup$
– Neil
11 hours ago












$begingroup$
@Neil Yes, indeed.
$endgroup$
– Flog Edoc
11 hours ago




$begingroup$
@Neil Yes, indeed.
$endgroup$
– Flog Edoc
11 hours ago












$begingroup$
A terminology issue (because terminology is important here): 'aaa' is not a subset/subsection/substring/subsequence of any permutation of 'abcd'. Every permutation of 'abcd' has exactly 1 'a' in it.
$endgroup$
– Chas Brown
10 hours ago






$begingroup$
A terminology issue (because terminology is important here): 'aaa' is not a subset/subsection/substring/subsequence of any permutation of 'abcd'. Every permutation of 'abcd' has exactly 1 'a' in it.
$endgroup$
– Chas Brown
10 hours ago












13 Answers
13






active

oldest

votes


















4












$begingroup$


Jelly,  10  5 bytes



ṗJẎQX


A monadic Link accepting a list of characters which yields a list of characters.



Try it online!



How?



ṗJẎQX - Link list of characters    e.g.  aabc
J - range of length [1,2,3,4]
ṗ - Cartesian power (vectorises) [[a,a,b,c],[aa,aa,ab,ac,aa,aa,ab,ac,ba,ba,bb,bc,ca,ca,cb,cc],[aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,baa,baa,bab,bac,baa,baa,bab,bac,bba,bba,bbb,bbc,bca,bca,bcb,bcc,caa,caa,cab,cac,caa,caa,cab,cac,cba,cba,cbb,cbc,cca,cca,ccb,ccc],[aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,bbaa,bbaa,bbab,bbac,bbaa,bbaa,bbab,bbac,bbba,bbba,bbbb,bbbc,bbca,bbca,bbcb,bbcc,bcaa,bcaa,bcab,bcac,bcaa,bcaa,bcab,bcac,bcba,bcba,bcbb,bcbc,bcca,bcca,bccb,bccc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,cbaa,cbaa,cbab,cbac,cbaa,cbaa,cbab,cbac,cbba,cbba,cbbb,cbbc,cbca,cbca,cbcb,cbcc,ccaa,ccaa,ccab,ccac,ccaa,ccaa,ccab,ccac,ccba,ccba,ccbb,ccbc,ccca,ccca,cccb,cccc]
Ẏ - tighten [a,a,b,c,aa,aa,ab,ac,aa,aa,ab,ac,ba,ba,bb,bc,ca,ca,cb,cc,aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,baa,baa,bab,bac,baa,baa,bab,bac,bba,bba,bbb,bbc,bca,bca,bcb,bcc,caa,caa,cab,cac,caa,caa,cab,cac,cba,cba,cbb,cbc,cca,cca,ccb,ccc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,bbaa,bbaa,bbab,bbac,bbaa,bbaa,bbab,bbac,bbba,bbba,bbbb,bbbc,bbca,bbca,bbcb,bbcc,bcaa,bcaa,bcab,bcac,bcaa,bcaa,bcab,bcac,bcba,bcba,bcbb,bcbc,bcca,bcca,bccb,bccc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,cbaa,cbaa,cbab,cbac,cbaa,cbaa,cbab,cbac,cbba,cbba,cbbb,cbbc,cbca,cbca,cbcb,cbcc,ccaa,ccaa,ccab,ccac,ccaa,ccaa,ccab,ccac,ccba,ccba,ccbb,ccbc,ccca,ccca,cccb,cccc]
Q - de-duplicate [a,b,c,aa,ab,ac,ba,bb,bc,ca,cb,cc,aaa,aab,aac,aba,abb,abc,aca,acb,acc,baa,bab,bac,bba,bbb,bbc,bca,bcb,bcc,caa,cab,cac,cba,cbb,cbc,cca,ccb,ccc,aaaa,aaab,aaac,aaba,aabb,aabc,aaca,aacb,aacc,abaa,abab,abac,abba,abbb,abbc,abca,abcb,abcc,acaa,acab,acac,acba,acbb,acbc,acca,accb,accc,baaa,baab,baac,baba,babb,babc,baca,bacb,bacc,bbaa,bbab,bbac,bbba,bbbb,bbbc,bbca,bbcb,bbcc,bcaa,bcab,bcac,bcba,bcbb,bcbc,bcca,bccb,bccc,caaa,caab,caac,caba,cabb,cabc,caca,cacb,cacc,cbaa,cbab,cbac,cbba,cbbb,cbbc,cbca,cbcb,cbcc,ccaa,ccab,ccac,ccba,ccbb,ccbc,ccca,cccb,cccc]
X - uniform random choice





share|improve this answer











$endgroup$













  • $begingroup$
    That fraction can be $frac1{2^{L+1}-2}$... ;P
    $endgroup$
    – Erik the Outgolfer
    16 hours ago



















3












$begingroup$


Brachylog, 8 bytes



⊇ᶠbṛ;?ṛw


Try it online!



Prints output directly instead of constraining the output variable, because for some reason this actually fails without the w at the end. Originally this used and the ∈& backtracking hack I used to implement bogosort, but I realized that it would be far saner to just use b instead.



       w    Print
ṛ a random one of
? the input
; or
ṛ a random element of
ᶠ every
⊇ sublist of
the input
b except the first one (which would be the input).





share|improve this answer









$endgroup$





















    3












    $begingroup$


    05AB1E, 6 bytes



    ā€ã˜ÙΩ


    Try it online!



    Explanation



    ā       # push [1 ... len(input)]
    ۋ # apply repeated cartesian product on each and input
    ˜ # flatten
    Ù # remove duplicates
    Ω # pick random string





    share|improve this answer











    $endgroup$





















      2












      $begingroup$


      Perl 6, 35 bytes





      {set($_,[X~] $_ xx$_).pick}o*.comb


      Try it online!



      Explanation:



      {                          }o*.comb  # Anonymous code block
      [ X~] $_ xx$_ # Find all combinations with repetition of the input
      # And most of the prefixes
      $_, # Add the singular characters
      set( ) # Remove duplicates
      .pick # And pick a random one





      share|improve this answer











      $endgroup$





















        1












        $begingroup$


        Japt, 10 9 bytes



        -1 byte from @Shaggy



        M¬©Uª¯UÊö




        M¬©Uª¯UÊö       Full Program
        M¬ Random number between 1 and 0 (50% => 1, 50% => 0)
        © If 1 then
        U Output the whole string
        ª Else
        ¯ Get a sub string from 0 to
        ö A positive random number lower than
        UÊ The length of the string


        Try it online!






        Japt, 9 bytes



        Removes chars at random position. Done by @Shaggy



        M¬©Uª®p2ö


        Try it online!






        share|improve this answer











        $endgroup$









        • 1




          $begingroup$
          Does this work for abcd --> ac?
          $endgroup$
          – AdmBorkBork
          17 hours ago










        • $begingroup$
          @AdmBorkBork No, it just returns a substring of the original. Since it is Removing a non-zero random number of characters from it. I assume it is valid
          $endgroup$
          – Luis felipe De jesus Munoz
          17 hours ago






        • 1




          $begingroup$
          9 bytes?
          $endgroup$
          – Shaggy
          17 hours ago






        • 1




          $begingroup$
          Or remove letters at random for the same byte count: tio.run/##y0osKPn/3/fQmkMrQw@tOrSuwOjwtv//lZzzU1IV3PNz0pQA
          $endgroup$
          – Shaggy
          17 hours ago










        • $begingroup$
          I don't think this is correct anymore
          $endgroup$
          – Jo King
          9 hours ago



















        1












        $begingroup$


        Python 2, 111 121 bytes





        lambda s:choice(g(list(set(s)),len(s)))
        from random import *
        g=lambda s,n:s+(n>1and[c+k for k in g(s,n-1)for c in s]or)


        Try it online!



        Takes any iterable (list, set, string, etc.) of either distinct characters or non-distinct characters as input. Outputs a non-empty string with the required distribution.



        g is a recursive function to generate a list of compliant strings.






        share|improve this answer











        $endgroup$













        • $begingroup$
          This is why I asked: will there be repeated chars in the input (which I think OP is now saying there will not be). Otherwise, easily fixed by, e.g., replacing g(s, ...) with g(list(set(s)), ...; but waiting on clarification. Anyway, for me, g is the interesting part; the rest is just I/O issues, in my opinion.
          $endgroup$
          – Chas Brown
          7 hours ago





















        0












        $begingroup$


        C (gcc), 68 65 bytes





        f(s,i)char*s;{for(;i<strlen(s);i++)rand()&1?putc(s[i],stdout):0;}


        Try it online!






        share|improve this answer











        $endgroup$













        • $begingroup$
          I don't think this is correct anymore
          $endgroup$
          – Jo King
          9 hours ago










        • $begingroup$
          If the op changed the rules that's a pity.
          $endgroup$
          – Natural Number Guy
          1 hour ago



















        0












        $begingroup$

        Java, 106 bytes



        void k(String a){a.chars().filter(value->Math.random()>.5).forEach(value->System.out.print((char)value));}





        share|improve this answer









        $endgroup$













        • $begingroup$
          Given a string like abc, there is no chance of the string cba appearing. Next, you can turn the function into a lambda, and you do not need to name all the lambda variables value, one letter names suffice. Something like: a->a.chars().filter(value->Math.random()>.5) since you do not need to print your output, though you still need to fix the first problem I listed
          $endgroup$
          – Embodiment of Ignorance
          11 hours ago





















        0












        $begingroup$


        R, 72 bytes





        sample(t<-unique(s<-scan(,"")),sample(n<-length(s),p=length(t)^(1:n)),T)


        Try it online!



        Input and output are vectors of characters. All possible outputs have equal probability.



        Explanation (ungolfed version):



        s<-scan(,"")                         # takes input as vector of characters
        n<-length(s)
        t<-unique(s)
        sample(t, # sample uniformly at random from the list of unique characters
        sample(n,p=length(t)^(1:n)), # with length k in 1..n chosen randomly such that P[k] is proportional to length(t)^k
        T) # the sampling is with replacement





        share|improve this answer











        $endgroup$





















          0












          $begingroup$

          T-SQL, 233 bytes



          DECLARE @ varchar(max)='abcd';

          WITH C as(SELECT DISTINCT substring(@,number+1,1)x FROM spt_values
          WHERE'P'=type and len(@)>number),D as(SELECT x,x y FROM c UNION ALL
          SELECT C.x,D.y+D.x FROM C JOIN D ON len(y)<len(@))SELECT
          top 1y FROM D GROUP BY y ORDER BY newid()


          Note the online version will always give the same result unlike MS-SQL Studio Management. This is because newid() always returns the same value in the online testing. This should work in Studio Management.



          Try it online ungolfed






          share|improve this answer









          $endgroup$





















            0












            $begingroup$


            Charcoal, 34 bytes



            ≔Φθ⁼κ⌕θιη≔⊕‽ΣEθXLη⊕κζWζ«§ηζ≔÷⊖ζLηζ


            Try it online! Link is to verbose version of code. Explanation:



            ≔Φθ⁼κ⌕θιη


            Extract the unique characters of the input. Let's call the number of unique characters n.



            ≔⊕‽ΣEθXLη⊕κζ


            Calculate the number of combinations for each possible length and take the sum. Then, pick a random number between 1 and this number (inclusive). This ensures that all combinations are equally likely (within the accuracy of the random number generator).



            Wζ«§ηζ≔÷⊖ζLηζ


            Convert the number into bijective base n, using the unique characters as the digits.






            share|improve this answer









            $endgroup$





















              0












              $begingroup$


              Wolfram Language (Mathematica), 41 bytes



              ""<>#&@*RandomChoice@*Subsets@*Characters


              Try it online!






              share|improve this answer









              $endgroup$





















                0












                $begingroup$


                MATLAB / Octave, 110 bytes



                Choose a random permutation of a subset of the input letters (with repetitions), whose random length is based on the probability of generating a word with that length.





                @(a)a(randi(numel(a),[find(cumsum(numel(a).^[1:numel(a)])>=randi(sum(numel(a).^[1:numel(a)])),1,'first'),1]));


                Try it online!






                share|improve this answer









                $endgroup$














                  Your Answer





                  StackExchange.ifUsing("editor", function () {
                  return StackExchange.using("mathjaxEditing", function () {
                  StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
                  StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
                  });
                  });
                  }, "mathjax-editing");

                  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: "200"
                  };
                  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: false,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: null,
                  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
                  });


                  }
                  });






                  Flog Edoc is a new contributor. Be nice, and check out our Code of Conduct.










                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f182735%2fto-string-or-not-to-string%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  13 Answers
                  13






                  active

                  oldest

                  votes








                  13 Answers
                  13






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  4












                  $begingroup$


                  Jelly,  10  5 bytes



                  ṗJẎQX


                  A monadic Link accepting a list of characters which yields a list of characters.



                  Try it online!



                  How?



                  ṗJẎQX - Link list of characters    e.g.  aabc
                  J - range of length [1,2,3,4]
                  ṗ - Cartesian power (vectorises) [[a,a,b,c],[aa,aa,ab,ac,aa,aa,ab,ac,ba,ba,bb,bc,ca,ca,cb,cc],[aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,baa,baa,bab,bac,baa,baa,bab,bac,bba,bba,bbb,bbc,bca,bca,bcb,bcc,caa,caa,cab,cac,caa,caa,cab,cac,cba,cba,cbb,cbc,cca,cca,ccb,ccc],[aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,bbaa,bbaa,bbab,bbac,bbaa,bbaa,bbab,bbac,bbba,bbba,bbbb,bbbc,bbca,bbca,bbcb,bbcc,bcaa,bcaa,bcab,bcac,bcaa,bcaa,bcab,bcac,bcba,bcba,bcbb,bcbc,bcca,bcca,bccb,bccc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,cbaa,cbaa,cbab,cbac,cbaa,cbaa,cbab,cbac,cbba,cbba,cbbb,cbbc,cbca,cbca,cbcb,cbcc,ccaa,ccaa,ccab,ccac,ccaa,ccaa,ccab,ccac,ccba,ccba,ccbb,ccbc,ccca,ccca,cccb,cccc]
                  Ẏ - tighten [a,a,b,c,aa,aa,ab,ac,aa,aa,ab,ac,ba,ba,bb,bc,ca,ca,cb,cc,aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,baa,baa,bab,bac,baa,baa,bab,bac,bba,bba,bbb,bbc,bca,bca,bcb,bcc,caa,caa,cab,cac,caa,caa,cab,cac,cba,cba,cbb,cbc,cca,cca,ccb,ccc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,bbaa,bbaa,bbab,bbac,bbaa,bbaa,bbab,bbac,bbba,bbba,bbbb,bbbc,bbca,bbca,bbcb,bbcc,bcaa,bcaa,bcab,bcac,bcaa,bcaa,bcab,bcac,bcba,bcba,bcbb,bcbc,bcca,bcca,bccb,bccc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,cbaa,cbaa,cbab,cbac,cbaa,cbaa,cbab,cbac,cbba,cbba,cbbb,cbbc,cbca,cbca,cbcb,cbcc,ccaa,ccaa,ccab,ccac,ccaa,ccaa,ccab,ccac,ccba,ccba,ccbb,ccbc,ccca,ccca,cccb,cccc]
                  Q - de-duplicate [a,b,c,aa,ab,ac,ba,bb,bc,ca,cb,cc,aaa,aab,aac,aba,abb,abc,aca,acb,acc,baa,bab,bac,bba,bbb,bbc,bca,bcb,bcc,caa,cab,cac,cba,cbb,cbc,cca,ccb,ccc,aaaa,aaab,aaac,aaba,aabb,aabc,aaca,aacb,aacc,abaa,abab,abac,abba,abbb,abbc,abca,abcb,abcc,acaa,acab,acac,acba,acbb,acbc,acca,accb,accc,baaa,baab,baac,baba,babb,babc,baca,bacb,bacc,bbaa,bbab,bbac,bbba,bbbb,bbbc,bbca,bbcb,bbcc,bcaa,bcab,bcac,bcba,bcbb,bcbc,bcca,bccb,bccc,caaa,caab,caac,caba,cabb,cabc,caca,cacb,cacc,cbaa,cbab,cbac,cbba,cbbb,cbbc,cbca,cbcb,cbcc,ccaa,ccab,ccac,ccba,ccbb,ccbc,ccca,cccb,cccc]
                  X - uniform random choice





                  share|improve this answer











                  $endgroup$













                  • $begingroup$
                    That fraction can be $frac1{2^{L+1}-2}$... ;P
                    $endgroup$
                    – Erik the Outgolfer
                    16 hours ago
















                  4












                  $begingroup$


                  Jelly,  10  5 bytes



                  ṗJẎQX


                  A monadic Link accepting a list of characters which yields a list of characters.



                  Try it online!



                  How?



                  ṗJẎQX - Link list of characters    e.g.  aabc
                  J - range of length [1,2,3,4]
                  ṗ - Cartesian power (vectorises) [[a,a,b,c],[aa,aa,ab,ac,aa,aa,ab,ac,ba,ba,bb,bc,ca,ca,cb,cc],[aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,baa,baa,bab,bac,baa,baa,bab,bac,bba,bba,bbb,bbc,bca,bca,bcb,bcc,caa,caa,cab,cac,caa,caa,cab,cac,cba,cba,cbb,cbc,cca,cca,ccb,ccc],[aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,bbaa,bbaa,bbab,bbac,bbaa,bbaa,bbab,bbac,bbba,bbba,bbbb,bbbc,bbca,bbca,bbcb,bbcc,bcaa,bcaa,bcab,bcac,bcaa,bcaa,bcab,bcac,bcba,bcba,bcbb,bcbc,bcca,bcca,bccb,bccc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,cbaa,cbaa,cbab,cbac,cbaa,cbaa,cbab,cbac,cbba,cbba,cbbb,cbbc,cbca,cbca,cbcb,cbcc,ccaa,ccaa,ccab,ccac,ccaa,ccaa,ccab,ccac,ccba,ccba,ccbb,ccbc,ccca,ccca,cccb,cccc]
                  Ẏ - tighten [a,a,b,c,aa,aa,ab,ac,aa,aa,ab,ac,ba,ba,bb,bc,ca,ca,cb,cc,aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,baa,baa,bab,bac,baa,baa,bab,bac,bba,bba,bbb,bbc,bca,bca,bcb,bcc,caa,caa,cab,cac,caa,caa,cab,cac,cba,cba,cbb,cbc,cca,cca,ccb,ccc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,bbaa,bbaa,bbab,bbac,bbaa,bbaa,bbab,bbac,bbba,bbba,bbbb,bbbc,bbca,bbca,bbcb,bbcc,bcaa,bcaa,bcab,bcac,bcaa,bcaa,bcab,bcac,bcba,bcba,bcbb,bcbc,bcca,bcca,bccb,bccc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,cbaa,cbaa,cbab,cbac,cbaa,cbaa,cbab,cbac,cbba,cbba,cbbb,cbbc,cbca,cbca,cbcb,cbcc,ccaa,ccaa,ccab,ccac,ccaa,ccaa,ccab,ccac,ccba,ccba,ccbb,ccbc,ccca,ccca,cccb,cccc]
                  Q - de-duplicate [a,b,c,aa,ab,ac,ba,bb,bc,ca,cb,cc,aaa,aab,aac,aba,abb,abc,aca,acb,acc,baa,bab,bac,bba,bbb,bbc,bca,bcb,bcc,caa,cab,cac,cba,cbb,cbc,cca,ccb,ccc,aaaa,aaab,aaac,aaba,aabb,aabc,aaca,aacb,aacc,abaa,abab,abac,abba,abbb,abbc,abca,abcb,abcc,acaa,acab,acac,acba,acbb,acbc,acca,accb,accc,baaa,baab,baac,baba,babb,babc,baca,bacb,bacc,bbaa,bbab,bbac,bbba,bbbb,bbbc,bbca,bbcb,bbcc,bcaa,bcab,bcac,bcba,bcbb,bcbc,bcca,bccb,bccc,caaa,caab,caac,caba,cabb,cabc,caca,cacb,cacc,cbaa,cbab,cbac,cbba,cbbb,cbbc,cbca,cbcb,cbcc,ccaa,ccab,ccac,ccba,ccbb,ccbc,ccca,cccb,cccc]
                  X - uniform random choice





                  share|improve this answer











                  $endgroup$













                  • $begingroup$
                    That fraction can be $frac1{2^{L+1}-2}$... ;P
                    $endgroup$
                    – Erik the Outgolfer
                    16 hours ago














                  4












                  4








                  4





                  $begingroup$


                  Jelly,  10  5 bytes



                  ṗJẎQX


                  A monadic Link accepting a list of characters which yields a list of characters.



                  Try it online!



                  How?



                  ṗJẎQX - Link list of characters    e.g.  aabc
                  J - range of length [1,2,3,4]
                  ṗ - Cartesian power (vectorises) [[a,a,b,c],[aa,aa,ab,ac,aa,aa,ab,ac,ba,ba,bb,bc,ca,ca,cb,cc],[aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,baa,baa,bab,bac,baa,baa,bab,bac,bba,bba,bbb,bbc,bca,bca,bcb,bcc,caa,caa,cab,cac,caa,caa,cab,cac,cba,cba,cbb,cbc,cca,cca,ccb,ccc],[aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,bbaa,bbaa,bbab,bbac,bbaa,bbaa,bbab,bbac,bbba,bbba,bbbb,bbbc,bbca,bbca,bbcb,bbcc,bcaa,bcaa,bcab,bcac,bcaa,bcaa,bcab,bcac,bcba,bcba,bcbb,bcbc,bcca,bcca,bccb,bccc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,cbaa,cbaa,cbab,cbac,cbaa,cbaa,cbab,cbac,cbba,cbba,cbbb,cbbc,cbca,cbca,cbcb,cbcc,ccaa,ccaa,ccab,ccac,ccaa,ccaa,ccab,ccac,ccba,ccba,ccbb,ccbc,ccca,ccca,cccb,cccc]
                  Ẏ - tighten [a,a,b,c,aa,aa,ab,ac,aa,aa,ab,ac,ba,ba,bb,bc,ca,ca,cb,cc,aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,baa,baa,bab,bac,baa,baa,bab,bac,bba,bba,bbb,bbc,bca,bca,bcb,bcc,caa,caa,cab,cac,caa,caa,cab,cac,cba,cba,cbb,cbc,cca,cca,ccb,ccc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,bbaa,bbaa,bbab,bbac,bbaa,bbaa,bbab,bbac,bbba,bbba,bbbb,bbbc,bbca,bbca,bbcb,bbcc,bcaa,bcaa,bcab,bcac,bcaa,bcaa,bcab,bcac,bcba,bcba,bcbb,bcbc,bcca,bcca,bccb,bccc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,cbaa,cbaa,cbab,cbac,cbaa,cbaa,cbab,cbac,cbba,cbba,cbbb,cbbc,cbca,cbca,cbcb,cbcc,ccaa,ccaa,ccab,ccac,ccaa,ccaa,ccab,ccac,ccba,ccba,ccbb,ccbc,ccca,ccca,cccb,cccc]
                  Q - de-duplicate [a,b,c,aa,ab,ac,ba,bb,bc,ca,cb,cc,aaa,aab,aac,aba,abb,abc,aca,acb,acc,baa,bab,bac,bba,bbb,bbc,bca,bcb,bcc,caa,cab,cac,cba,cbb,cbc,cca,ccb,ccc,aaaa,aaab,aaac,aaba,aabb,aabc,aaca,aacb,aacc,abaa,abab,abac,abba,abbb,abbc,abca,abcb,abcc,acaa,acab,acac,acba,acbb,acbc,acca,accb,accc,baaa,baab,baac,baba,babb,babc,baca,bacb,bacc,bbaa,bbab,bbac,bbba,bbbb,bbbc,bbca,bbcb,bbcc,bcaa,bcab,bcac,bcba,bcbb,bcbc,bcca,bccb,bccc,caaa,caab,caac,caba,cabb,cabc,caca,cacb,cacc,cbaa,cbab,cbac,cbba,cbbb,cbbc,cbca,cbcb,cbcc,ccaa,ccab,ccac,ccba,ccbb,ccbc,ccca,cccb,cccc]
                  X - uniform random choice





                  share|improve this answer











                  $endgroup$




                  Jelly,  10  5 bytes



                  ṗJẎQX


                  A monadic Link accepting a list of characters which yields a list of characters.



                  Try it online!



                  How?



                  ṗJẎQX - Link list of characters    e.g.  aabc
                  J - range of length [1,2,3,4]
                  ṗ - Cartesian power (vectorises) [[a,a,b,c],[aa,aa,ab,ac,aa,aa,ab,ac,ba,ba,bb,bc,ca,ca,cb,cc],[aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,baa,baa,bab,bac,baa,baa,bab,bac,bba,bba,bbb,bbc,bca,bca,bcb,bcc,caa,caa,cab,cac,caa,caa,cab,cac,cba,cba,cbb,cbc,cca,cca,ccb,ccc],[aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,bbaa,bbaa,bbab,bbac,bbaa,bbaa,bbab,bbac,bbba,bbba,bbbb,bbbc,bbca,bbca,bbcb,bbcc,bcaa,bcaa,bcab,bcac,bcaa,bcaa,bcab,bcac,bcba,bcba,bcbb,bcbc,bcca,bcca,bccb,bccc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,cbaa,cbaa,cbab,cbac,cbaa,cbaa,cbab,cbac,cbba,cbba,cbbb,cbbc,cbca,cbca,cbcb,cbcc,ccaa,ccaa,ccab,ccac,ccaa,ccaa,ccab,ccac,ccba,ccba,ccbb,ccbc,ccca,ccca,cccb,cccc]
                  Ẏ - tighten [a,a,b,c,aa,aa,ab,ac,aa,aa,ab,ac,ba,ba,bb,bc,ca,ca,cb,cc,aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,aaa,aaa,aab,aac,aaa,aaa,aab,aac,aba,aba,abb,abc,aca,aca,acb,acc,baa,baa,bab,bac,baa,baa,bab,bac,bba,bba,bbb,bbc,bca,bca,bcb,bcc,caa,caa,cab,cac,caa,caa,cab,cac,cba,cba,cbb,cbc,cca,cca,ccb,ccc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,aaaa,aaaa,aaab,aaac,aaaa,aaaa,aaab,aaac,aaba,aaba,aabb,aabc,aaca,aaca,aacb,aacc,abaa,abaa,abab,abac,abaa,abaa,abab,abac,abba,abba,abbb,abbc,abca,abca,abcb,abcc,acaa,acaa,acab,acac,acaa,acaa,acab,acac,acba,acba,acbb,acbc,acca,acca,accb,accc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,baaa,baaa,baab,baac,baaa,baaa,baab,baac,baba,baba,babb,babc,baca,baca,bacb,bacc,bbaa,bbaa,bbab,bbac,bbaa,bbaa,bbab,bbac,bbba,bbba,bbbb,bbbc,bbca,bbca,bbcb,bbcc,bcaa,bcaa,bcab,bcac,bcaa,bcaa,bcab,bcac,bcba,bcba,bcbb,bcbc,bcca,bcca,bccb,bccc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,caaa,caaa,caab,caac,caaa,caaa,caab,caac,caba,caba,cabb,cabc,caca,caca,cacb,cacc,cbaa,cbaa,cbab,cbac,cbaa,cbaa,cbab,cbac,cbba,cbba,cbbb,cbbc,cbca,cbca,cbcb,cbcc,ccaa,ccaa,ccab,ccac,ccaa,ccaa,ccab,ccac,ccba,ccba,ccbb,ccbc,ccca,ccca,cccb,cccc]
                  Q - de-duplicate [a,b,c,aa,ab,ac,ba,bb,bc,ca,cb,cc,aaa,aab,aac,aba,abb,abc,aca,acb,acc,baa,bab,bac,bba,bbb,bbc,bca,bcb,bcc,caa,cab,cac,cba,cbb,cbc,cca,ccb,ccc,aaaa,aaab,aaac,aaba,aabb,aabc,aaca,aacb,aacc,abaa,abab,abac,abba,abbb,abbc,abca,abcb,abcc,acaa,acab,acac,acba,acbb,acbc,acca,accb,accc,baaa,baab,baac,baba,babb,babc,baca,bacb,bacc,bbaa,bbab,bbac,bbba,bbbb,bbbc,bbca,bbcb,bbcc,bcaa,bcab,bcac,bcba,bcbb,bcbc,bcca,bccb,bccc,caaa,caab,caac,caba,cabb,cabc,caca,cacb,cacc,cbaa,cbab,cbac,cbba,cbbb,cbbc,cbca,cbcb,cbcc,ccaa,ccab,ccac,ccba,ccbb,ccbc,ccca,cccb,cccc]
                  X - uniform random choice






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 14 hours ago

























                  answered 17 hours ago









                  Jonathan AllanJonathan Allan

                  53.7k535173




                  53.7k535173












                  • $begingroup$
                    That fraction can be $frac1{2^{L+1}-2}$... ;P
                    $endgroup$
                    – Erik the Outgolfer
                    16 hours ago


















                  • $begingroup$
                    That fraction can be $frac1{2^{L+1}-2}$... ;P
                    $endgroup$
                    – Erik the Outgolfer
                    16 hours ago
















                  $begingroup$
                  That fraction can be $frac1{2^{L+1}-2}$... ;P
                  $endgroup$
                  – Erik the Outgolfer
                  16 hours ago




                  $begingroup$
                  That fraction can be $frac1{2^{L+1}-2}$... ;P
                  $endgroup$
                  – Erik the Outgolfer
                  16 hours ago











                  3












                  $begingroup$


                  Brachylog, 8 bytes



                  ⊇ᶠbṛ;?ṛw


                  Try it online!



                  Prints output directly instead of constraining the output variable, because for some reason this actually fails without the w at the end. Originally this used and the ∈& backtracking hack I used to implement bogosort, but I realized that it would be far saner to just use b instead.



                         w    Print
                  ṛ a random one of
                  ? the input
                  ; or
                  ṛ a random element of
                  ᶠ every
                  ⊇ sublist of
                  the input
                  b except the first one (which would be the input).





                  share|improve this answer









                  $endgroup$


















                    3












                    $begingroup$


                    Brachylog, 8 bytes



                    ⊇ᶠbṛ;?ṛw


                    Try it online!



                    Prints output directly instead of constraining the output variable, because for some reason this actually fails without the w at the end. Originally this used and the ∈& backtracking hack I used to implement bogosort, but I realized that it would be far saner to just use b instead.



                           w    Print
                    ṛ a random one of
                    ? the input
                    ; or
                    ṛ a random element of
                    ᶠ every
                    ⊇ sublist of
                    the input
                    b except the first one (which would be the input).





                    share|improve this answer









                    $endgroup$
















                      3












                      3








                      3





                      $begingroup$


                      Brachylog, 8 bytes



                      ⊇ᶠbṛ;?ṛw


                      Try it online!



                      Prints output directly instead of constraining the output variable, because for some reason this actually fails without the w at the end. Originally this used and the ∈& backtracking hack I used to implement bogosort, but I realized that it would be far saner to just use b instead.



                             w    Print
                      ṛ a random one of
                      ? the input
                      ; or
                      ṛ a random element of
                      ᶠ every
                      ⊇ sublist of
                      the input
                      b except the first one (which would be the input).





                      share|improve this answer









                      $endgroup$




                      Brachylog, 8 bytes



                      ⊇ᶠbṛ;?ṛw


                      Try it online!



                      Prints output directly instead of constraining the output variable, because for some reason this actually fails without the w at the end. Originally this used and the ∈& backtracking hack I used to implement bogosort, but I realized that it would be far saner to just use b instead.



                             w    Print
                      ṛ a random one of
                      ? the input
                      ; or
                      ṛ a random element of
                      ᶠ every
                      ⊇ sublist of
                      the input
                      b except the first one (which would be the input).






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered 16 hours ago









                      Unrelated StringUnrelated String

                      1,571312




                      1,571312























                          3












                          $begingroup$


                          05AB1E, 6 bytes



                          ā€ã˜ÙΩ


                          Try it online!



                          Explanation



                          ā       # push [1 ... len(input)]
                          ۋ # apply repeated cartesian product on each and input
                          ˜ # flatten
                          Ù # remove duplicates
                          Ω # pick random string





                          share|improve this answer











                          $endgroup$


















                            3












                            $begingroup$


                            05AB1E, 6 bytes



                            ā€ã˜ÙΩ


                            Try it online!



                            Explanation



                            ā       # push [1 ... len(input)]
                            ۋ # apply repeated cartesian product on each and input
                            ˜ # flatten
                            Ù # remove duplicates
                            Ω # pick random string





                            share|improve this answer











                            $endgroup$
















                              3












                              3








                              3





                              $begingroup$


                              05AB1E, 6 bytes



                              ā€ã˜ÙΩ


                              Try it online!



                              Explanation



                              ā       # push [1 ... len(input)]
                              ۋ # apply repeated cartesian product on each and input
                              ˜ # flatten
                              Ù # remove duplicates
                              Ω # pick random string





                              share|improve this answer











                              $endgroup$




                              05AB1E, 6 bytes



                              ā€ã˜ÙΩ


                              Try it online!



                              Explanation



                              ā       # push [1 ... len(input)]
                              ۋ # apply repeated cartesian product on each and input
                              ˜ # flatten
                              Ù # remove duplicates
                              Ω # pick random string






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited 4 hours ago

























                              answered 16 hours ago









                              EmignaEmigna

                              47.4k433144




                              47.4k433144























                                  2












                                  $begingroup$


                                  Perl 6, 35 bytes





                                  {set($_,[X~] $_ xx$_).pick}o*.comb


                                  Try it online!



                                  Explanation:



                                  {                          }o*.comb  # Anonymous code block
                                  [ X~] $_ xx$_ # Find all combinations with repetition of the input
                                  # And most of the prefixes
                                  $_, # Add the singular characters
                                  set( ) # Remove duplicates
                                  .pick # And pick a random one





                                  share|improve this answer











                                  $endgroup$


















                                    2












                                    $begingroup$


                                    Perl 6, 35 bytes





                                    {set($_,[X~] $_ xx$_).pick}o*.comb


                                    Try it online!



                                    Explanation:



                                    {                          }o*.comb  # Anonymous code block
                                    [ X~] $_ xx$_ # Find all combinations with repetition of the input
                                    # And most of the prefixes
                                    $_, # Add the singular characters
                                    set( ) # Remove duplicates
                                    .pick # And pick a random one





                                    share|improve this answer











                                    $endgroup$
















                                      2












                                      2








                                      2





                                      $begingroup$


                                      Perl 6, 35 bytes





                                      {set($_,[X~] $_ xx$_).pick}o*.comb


                                      Try it online!



                                      Explanation:



                                      {                          }o*.comb  # Anonymous code block
                                      [ X~] $_ xx$_ # Find all combinations with repetition of the input
                                      # And most of the prefixes
                                      $_, # Add the singular characters
                                      set( ) # Remove duplicates
                                      .pick # And pick a random one





                                      share|improve this answer











                                      $endgroup$




                                      Perl 6, 35 bytes





                                      {set($_,[X~] $_ xx$_).pick}o*.comb


                                      Try it online!



                                      Explanation:



                                      {                          }o*.comb  # Anonymous code block
                                      [ X~] $_ xx$_ # Find all combinations with repetition of the input
                                      # And most of the prefixes
                                      $_, # Add the singular characters
                                      set( ) # Remove duplicates
                                      .pick # And pick a random one






                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited 5 hours ago

























                                      answered 10 hours ago









                                      Jo KingJo King

                                      26.4k364130




                                      26.4k364130























                                          1












                                          $begingroup$


                                          Japt, 10 9 bytes



                                          -1 byte from @Shaggy



                                          M¬©Uª¯UÊö




                                          M¬©Uª¯UÊö       Full Program
                                          M¬ Random number between 1 and 0 (50% => 1, 50% => 0)
                                          © If 1 then
                                          U Output the whole string
                                          ª Else
                                          ¯ Get a sub string from 0 to
                                          ö A positive random number lower than
                                          UÊ The length of the string


                                          Try it online!






                                          Japt, 9 bytes



                                          Removes chars at random position. Done by @Shaggy



                                          M¬©Uª®p2ö


                                          Try it online!






                                          share|improve this answer











                                          $endgroup$









                                          • 1




                                            $begingroup$
                                            Does this work for abcd --> ac?
                                            $endgroup$
                                            – AdmBorkBork
                                            17 hours ago










                                          • $begingroup$
                                            @AdmBorkBork No, it just returns a substring of the original. Since it is Removing a non-zero random number of characters from it. I assume it is valid
                                            $endgroup$
                                            – Luis felipe De jesus Munoz
                                            17 hours ago






                                          • 1




                                            $begingroup$
                                            9 bytes?
                                            $endgroup$
                                            – Shaggy
                                            17 hours ago






                                          • 1




                                            $begingroup$
                                            Or remove letters at random for the same byte count: tio.run/##y0osKPn/3/fQmkMrQw@tOrSuwOjwtv//lZzzU1IV3PNz0pQA
                                            $endgroup$
                                            – Shaggy
                                            17 hours ago










                                          • $begingroup$
                                            I don't think this is correct anymore
                                            $endgroup$
                                            – Jo King
                                            9 hours ago
















                                          1












                                          $begingroup$


                                          Japt, 10 9 bytes



                                          -1 byte from @Shaggy



                                          M¬©Uª¯UÊö




                                          M¬©Uª¯UÊö       Full Program
                                          M¬ Random number between 1 and 0 (50% => 1, 50% => 0)
                                          © If 1 then
                                          U Output the whole string
                                          ª Else
                                          ¯ Get a sub string from 0 to
                                          ö A positive random number lower than
                                          UÊ The length of the string


                                          Try it online!






                                          Japt, 9 bytes



                                          Removes chars at random position. Done by @Shaggy



                                          M¬©Uª®p2ö


                                          Try it online!






                                          share|improve this answer











                                          $endgroup$









                                          • 1




                                            $begingroup$
                                            Does this work for abcd --> ac?
                                            $endgroup$
                                            – AdmBorkBork
                                            17 hours ago










                                          • $begingroup$
                                            @AdmBorkBork No, it just returns a substring of the original. Since it is Removing a non-zero random number of characters from it. I assume it is valid
                                            $endgroup$
                                            – Luis felipe De jesus Munoz
                                            17 hours ago






                                          • 1




                                            $begingroup$
                                            9 bytes?
                                            $endgroup$
                                            – Shaggy
                                            17 hours ago






                                          • 1




                                            $begingroup$
                                            Or remove letters at random for the same byte count: tio.run/##y0osKPn/3/fQmkMrQw@tOrSuwOjwtv//lZzzU1IV3PNz0pQA
                                            $endgroup$
                                            – Shaggy
                                            17 hours ago










                                          • $begingroup$
                                            I don't think this is correct anymore
                                            $endgroup$
                                            – Jo King
                                            9 hours ago














                                          1












                                          1








                                          1





                                          $begingroup$


                                          Japt, 10 9 bytes



                                          -1 byte from @Shaggy



                                          M¬©Uª¯UÊö




                                          M¬©Uª¯UÊö       Full Program
                                          M¬ Random number between 1 and 0 (50% => 1, 50% => 0)
                                          © If 1 then
                                          U Output the whole string
                                          ª Else
                                          ¯ Get a sub string from 0 to
                                          ö A positive random number lower than
                                          UÊ The length of the string


                                          Try it online!






                                          Japt, 9 bytes



                                          Removes chars at random position. Done by @Shaggy



                                          M¬©Uª®p2ö


                                          Try it online!






                                          share|improve this answer











                                          $endgroup$




                                          Japt, 10 9 bytes



                                          -1 byte from @Shaggy



                                          M¬©Uª¯UÊö




                                          M¬©Uª¯UÊö       Full Program
                                          M¬ Random number between 1 and 0 (50% => 1, 50% => 0)
                                          © If 1 then
                                          U Output the whole string
                                          ª Else
                                          ¯ Get a sub string from 0 to
                                          ö A positive random number lower than
                                          UÊ The length of the string


                                          Try it online!






                                          Japt, 9 bytes



                                          Removes chars at random position. Done by @Shaggy



                                          M¬©Uª®p2ö


                                          Try it online!







                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited 16 hours ago

























                                          answered 17 hours ago









                                          Luis felipe De jesus MunozLuis felipe De jesus Munoz

                                          5,71821671




                                          5,71821671








                                          • 1




                                            $begingroup$
                                            Does this work for abcd --> ac?
                                            $endgroup$
                                            – AdmBorkBork
                                            17 hours ago










                                          • $begingroup$
                                            @AdmBorkBork No, it just returns a substring of the original. Since it is Removing a non-zero random number of characters from it. I assume it is valid
                                            $endgroup$
                                            – Luis felipe De jesus Munoz
                                            17 hours ago






                                          • 1




                                            $begingroup$
                                            9 bytes?
                                            $endgroup$
                                            – Shaggy
                                            17 hours ago






                                          • 1




                                            $begingroup$
                                            Or remove letters at random for the same byte count: tio.run/##y0osKPn/3/fQmkMrQw@tOrSuwOjwtv//lZzzU1IV3PNz0pQA
                                            $endgroup$
                                            – Shaggy
                                            17 hours ago










                                          • $begingroup$
                                            I don't think this is correct anymore
                                            $endgroup$
                                            – Jo King
                                            9 hours ago














                                          • 1




                                            $begingroup$
                                            Does this work for abcd --> ac?
                                            $endgroup$
                                            – AdmBorkBork
                                            17 hours ago










                                          • $begingroup$
                                            @AdmBorkBork No, it just returns a substring of the original. Since it is Removing a non-zero random number of characters from it. I assume it is valid
                                            $endgroup$
                                            – Luis felipe De jesus Munoz
                                            17 hours ago






                                          • 1




                                            $begingroup$
                                            9 bytes?
                                            $endgroup$
                                            – Shaggy
                                            17 hours ago






                                          • 1




                                            $begingroup$
                                            Or remove letters at random for the same byte count: tio.run/##y0osKPn/3/fQmkMrQw@tOrSuwOjwtv//lZzzU1IV3PNz0pQA
                                            $endgroup$
                                            – Shaggy
                                            17 hours ago










                                          • $begingroup$
                                            I don't think this is correct anymore
                                            $endgroup$
                                            – Jo King
                                            9 hours ago








                                          1




                                          1




                                          $begingroup$
                                          Does this work for abcd --> ac?
                                          $endgroup$
                                          – AdmBorkBork
                                          17 hours ago




                                          $begingroup$
                                          Does this work for abcd --> ac?
                                          $endgroup$
                                          – AdmBorkBork
                                          17 hours ago












                                          $begingroup$
                                          @AdmBorkBork No, it just returns a substring of the original. Since it is Removing a non-zero random number of characters from it. I assume it is valid
                                          $endgroup$
                                          – Luis felipe De jesus Munoz
                                          17 hours ago




                                          $begingroup$
                                          @AdmBorkBork No, it just returns a substring of the original. Since it is Removing a non-zero random number of characters from it. I assume it is valid
                                          $endgroup$
                                          – Luis felipe De jesus Munoz
                                          17 hours ago




                                          1




                                          1




                                          $begingroup$
                                          9 bytes?
                                          $endgroup$
                                          – Shaggy
                                          17 hours ago




                                          $begingroup$
                                          9 bytes?
                                          $endgroup$
                                          – Shaggy
                                          17 hours ago




                                          1




                                          1




                                          $begingroup$
                                          Or remove letters at random for the same byte count: tio.run/##y0osKPn/3/fQmkMrQw@tOrSuwOjwtv//lZzzU1IV3PNz0pQA
                                          $endgroup$
                                          – Shaggy
                                          17 hours ago




                                          $begingroup$
                                          Or remove letters at random for the same byte count: tio.run/##y0osKPn/3/fQmkMrQw@tOrSuwOjwtv//lZzzU1IV3PNz0pQA
                                          $endgroup$
                                          – Shaggy
                                          17 hours ago












                                          $begingroup$
                                          I don't think this is correct anymore
                                          $endgroup$
                                          – Jo King
                                          9 hours ago




                                          $begingroup$
                                          I don't think this is correct anymore
                                          $endgroup$
                                          – Jo King
                                          9 hours ago











                                          1












                                          $begingroup$


                                          Python 2, 111 121 bytes





                                          lambda s:choice(g(list(set(s)),len(s)))
                                          from random import *
                                          g=lambda s,n:s+(n>1and[c+k for k in g(s,n-1)for c in s]or)


                                          Try it online!



                                          Takes any iterable (list, set, string, etc.) of either distinct characters or non-distinct characters as input. Outputs a non-empty string with the required distribution.



                                          g is a recursive function to generate a list of compliant strings.






                                          share|improve this answer











                                          $endgroup$













                                          • $begingroup$
                                            This is why I asked: will there be repeated chars in the input (which I think OP is now saying there will not be). Otherwise, easily fixed by, e.g., replacing g(s, ...) with g(list(set(s)), ...; but waiting on clarification. Anyway, for me, g is the interesting part; the rest is just I/O issues, in my opinion.
                                            $endgroup$
                                            – Chas Brown
                                            7 hours ago


















                                          1












                                          $begingroup$


                                          Python 2, 111 121 bytes





                                          lambda s:choice(g(list(set(s)),len(s)))
                                          from random import *
                                          g=lambda s,n:s+(n>1and[c+k for k in g(s,n-1)for c in s]or)


                                          Try it online!



                                          Takes any iterable (list, set, string, etc.) of either distinct characters or non-distinct characters as input. Outputs a non-empty string with the required distribution.



                                          g is a recursive function to generate a list of compliant strings.






                                          share|improve this answer











                                          $endgroup$













                                          • $begingroup$
                                            This is why I asked: will there be repeated chars in the input (which I think OP is now saying there will not be). Otherwise, easily fixed by, e.g., replacing g(s, ...) with g(list(set(s)), ...; but waiting on clarification. Anyway, for me, g is the interesting part; the rest is just I/O issues, in my opinion.
                                            $endgroup$
                                            – Chas Brown
                                            7 hours ago
















                                          1












                                          1








                                          1





                                          $begingroup$


                                          Python 2, 111 121 bytes





                                          lambda s:choice(g(list(set(s)),len(s)))
                                          from random import *
                                          g=lambda s,n:s+(n>1and[c+k for k in g(s,n-1)for c in s]or)


                                          Try it online!



                                          Takes any iterable (list, set, string, etc.) of either distinct characters or non-distinct characters as input. Outputs a non-empty string with the required distribution.



                                          g is a recursive function to generate a list of compliant strings.






                                          share|improve this answer











                                          $endgroup$




                                          Python 2, 111 121 bytes





                                          lambda s:choice(g(list(set(s)),len(s)))
                                          from random import *
                                          g=lambda s,n:s+(n>1and[c+k for k in g(s,n-1)for c in s]or)


                                          Try it online!



                                          Takes any iterable (list, set, string, etc.) of either distinct characters or non-distinct characters as input. Outputs a non-empty string with the required distribution.



                                          g is a recursive function to generate a list of compliant strings.







                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited 6 hours ago

























                                          answered 8 hours ago









                                          Chas BrownChas Brown

                                          5,1391523




                                          5,1391523












                                          • $begingroup$
                                            This is why I asked: will there be repeated chars in the input (which I think OP is now saying there will not be). Otherwise, easily fixed by, e.g., replacing g(s, ...) with g(list(set(s)), ...; but waiting on clarification. Anyway, for me, g is the interesting part; the rest is just I/O issues, in my opinion.
                                            $endgroup$
                                            – Chas Brown
                                            7 hours ago




















                                          • $begingroup$
                                            This is why I asked: will there be repeated chars in the input (which I think OP is now saying there will not be). Otherwise, easily fixed by, e.g., replacing g(s, ...) with g(list(set(s)), ...; but waiting on clarification. Anyway, for me, g is the interesting part; the rest is just I/O issues, in my opinion.
                                            $endgroup$
                                            – Chas Brown
                                            7 hours ago


















                                          $begingroup$
                                          This is why I asked: will there be repeated chars in the input (which I think OP is now saying there will not be). Otherwise, easily fixed by, e.g., replacing g(s, ...) with g(list(set(s)), ...; but waiting on clarification. Anyway, for me, g is the interesting part; the rest is just I/O issues, in my opinion.
                                          $endgroup$
                                          – Chas Brown
                                          7 hours ago






                                          $begingroup$
                                          This is why I asked: will there be repeated chars in the input (which I think OP is now saying there will not be). Otherwise, easily fixed by, e.g., replacing g(s, ...) with g(list(set(s)), ...; but waiting on clarification. Anyway, for me, g is the interesting part; the rest is just I/O issues, in my opinion.
                                          $endgroup$
                                          – Chas Brown
                                          7 hours ago













                                          0












                                          $begingroup$


                                          C (gcc), 68 65 bytes





                                          f(s,i)char*s;{for(;i<strlen(s);i++)rand()&1?putc(s[i],stdout):0;}


                                          Try it online!






                                          share|improve this answer











                                          $endgroup$













                                          • $begingroup$
                                            I don't think this is correct anymore
                                            $endgroup$
                                            – Jo King
                                            9 hours ago










                                          • $begingroup$
                                            If the op changed the rules that's a pity.
                                            $endgroup$
                                            – Natural Number Guy
                                            1 hour ago
















                                          0












                                          $begingroup$


                                          C (gcc), 68 65 bytes





                                          f(s,i)char*s;{for(;i<strlen(s);i++)rand()&1?putc(s[i],stdout):0;}


                                          Try it online!






                                          share|improve this answer











                                          $endgroup$













                                          • $begingroup$
                                            I don't think this is correct anymore
                                            $endgroup$
                                            – Jo King
                                            9 hours ago










                                          • $begingroup$
                                            If the op changed the rules that's a pity.
                                            $endgroup$
                                            – Natural Number Guy
                                            1 hour ago














                                          0












                                          0








                                          0





                                          $begingroup$


                                          C (gcc), 68 65 bytes





                                          f(s,i)char*s;{for(;i<strlen(s);i++)rand()&1?putc(s[i],stdout):0;}


                                          Try it online!






                                          share|improve this answer











                                          $endgroup$




                                          C (gcc), 68 65 bytes





                                          f(s,i)char*s;{for(;i<strlen(s);i++)rand()&1?putc(s[i],stdout):0;}


                                          Try it online!







                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited 16 hours ago

























                                          answered 17 hours ago









                                          Natural Number GuyNatural Number Guy

                                          1516




                                          1516












                                          • $begingroup$
                                            I don't think this is correct anymore
                                            $endgroup$
                                            – Jo King
                                            9 hours ago










                                          • $begingroup$
                                            If the op changed the rules that's a pity.
                                            $endgroup$
                                            – Natural Number Guy
                                            1 hour ago


















                                          • $begingroup$
                                            I don't think this is correct anymore
                                            $endgroup$
                                            – Jo King
                                            9 hours ago










                                          • $begingroup$
                                            If the op changed the rules that's a pity.
                                            $endgroup$
                                            – Natural Number Guy
                                            1 hour ago
















                                          $begingroup$
                                          I don't think this is correct anymore
                                          $endgroup$
                                          – Jo King
                                          9 hours ago




                                          $begingroup$
                                          I don't think this is correct anymore
                                          $endgroup$
                                          – Jo King
                                          9 hours ago












                                          $begingroup$
                                          If the op changed the rules that's a pity.
                                          $endgroup$
                                          – Natural Number Guy
                                          1 hour ago




                                          $begingroup$
                                          If the op changed the rules that's a pity.
                                          $endgroup$
                                          – Natural Number Guy
                                          1 hour ago











                                          0












                                          $begingroup$

                                          Java, 106 bytes



                                          void k(String a){a.chars().filter(value->Math.random()>.5).forEach(value->System.out.print((char)value));}





                                          share|improve this answer









                                          $endgroup$













                                          • $begingroup$
                                            Given a string like abc, there is no chance of the string cba appearing. Next, you can turn the function into a lambda, and you do not need to name all the lambda variables value, one letter names suffice. Something like: a->a.chars().filter(value->Math.random()>.5) since you do not need to print your output, though you still need to fix the first problem I listed
                                            $endgroup$
                                            – Embodiment of Ignorance
                                            11 hours ago


















                                          0












                                          $begingroup$

                                          Java, 106 bytes



                                          void k(String a){a.chars().filter(value->Math.random()>.5).forEach(value->System.out.print((char)value));}





                                          share|improve this answer









                                          $endgroup$













                                          • $begingroup$
                                            Given a string like abc, there is no chance of the string cba appearing. Next, you can turn the function into a lambda, and you do not need to name all the lambda variables value, one letter names suffice. Something like: a->a.chars().filter(value->Math.random()>.5) since you do not need to print your output, though you still need to fix the first problem I listed
                                            $endgroup$
                                            – Embodiment of Ignorance
                                            11 hours ago
















                                          0












                                          0








                                          0





                                          $begingroup$

                                          Java, 106 bytes



                                          void k(String a){a.chars().filter(value->Math.random()>.5).forEach(value->System.out.print((char)value));}





                                          share|improve this answer









                                          $endgroup$



                                          Java, 106 bytes



                                          void k(String a){a.chars().filter(value->Math.random()>.5).forEach(value->System.out.print((char)value));}






                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered 16 hours ago









                                          Ilya GazmanIlya Gazman

                                          479313




                                          479313












                                          • $begingroup$
                                            Given a string like abc, there is no chance of the string cba appearing. Next, you can turn the function into a lambda, and you do not need to name all the lambda variables value, one letter names suffice. Something like: a->a.chars().filter(value->Math.random()>.5) since you do not need to print your output, though you still need to fix the first problem I listed
                                            $endgroup$
                                            – Embodiment of Ignorance
                                            11 hours ago




















                                          • $begingroup$
                                            Given a string like abc, there is no chance of the string cba appearing. Next, you can turn the function into a lambda, and you do not need to name all the lambda variables value, one letter names suffice. Something like: a->a.chars().filter(value->Math.random()>.5) since you do not need to print your output, though you still need to fix the first problem I listed
                                            $endgroup$
                                            – Embodiment of Ignorance
                                            11 hours ago


















                                          $begingroup$
                                          Given a string like abc, there is no chance of the string cba appearing. Next, you can turn the function into a lambda, and you do not need to name all the lambda variables value, one letter names suffice. Something like: a->a.chars().filter(value->Math.random()>.5) since you do not need to print your output, though you still need to fix the first problem I listed
                                          $endgroup$
                                          – Embodiment of Ignorance
                                          11 hours ago






                                          $begingroup$
                                          Given a string like abc, there is no chance of the string cba appearing. Next, you can turn the function into a lambda, and you do not need to name all the lambda variables value, one letter names suffice. Something like: a->a.chars().filter(value->Math.random()>.5) since you do not need to print your output, though you still need to fix the first problem I listed
                                          $endgroup$
                                          – Embodiment of Ignorance
                                          11 hours ago













                                          0












                                          $begingroup$


                                          R, 72 bytes





                                          sample(t<-unique(s<-scan(,"")),sample(n<-length(s),p=length(t)^(1:n)),T)


                                          Try it online!



                                          Input and output are vectors of characters. All possible outputs have equal probability.



                                          Explanation (ungolfed version):



                                          s<-scan(,"")                         # takes input as vector of characters
                                          n<-length(s)
                                          t<-unique(s)
                                          sample(t, # sample uniformly at random from the list of unique characters
                                          sample(n,p=length(t)^(1:n)), # with length k in 1..n chosen randomly such that P[k] is proportional to length(t)^k
                                          T) # the sampling is with replacement





                                          share|improve this answer











                                          $endgroup$


















                                            0












                                            $begingroup$


                                            R, 72 bytes





                                            sample(t<-unique(s<-scan(,"")),sample(n<-length(s),p=length(t)^(1:n)),T)


                                            Try it online!



                                            Input and output are vectors of characters. All possible outputs have equal probability.



                                            Explanation (ungolfed version):



                                            s<-scan(,"")                         # takes input as vector of characters
                                            n<-length(s)
                                            t<-unique(s)
                                            sample(t, # sample uniformly at random from the list of unique characters
                                            sample(n,p=length(t)^(1:n)), # with length k in 1..n chosen randomly such that P[k] is proportional to length(t)^k
                                            T) # the sampling is with replacement





                                            share|improve this answer











                                            $endgroup$
















                                              0












                                              0








                                              0





                                              $begingroup$


                                              R, 72 bytes





                                              sample(t<-unique(s<-scan(,"")),sample(n<-length(s),p=length(t)^(1:n)),T)


                                              Try it online!



                                              Input and output are vectors of characters. All possible outputs have equal probability.



                                              Explanation (ungolfed version):



                                              s<-scan(,"")                         # takes input as vector of characters
                                              n<-length(s)
                                              t<-unique(s)
                                              sample(t, # sample uniformly at random from the list of unique characters
                                              sample(n,p=length(t)^(1:n)), # with length k in 1..n chosen randomly such that P[k] is proportional to length(t)^k
                                              T) # the sampling is with replacement





                                              share|improve this answer











                                              $endgroup$




                                              R, 72 bytes





                                              sample(t<-unique(s<-scan(,"")),sample(n<-length(s),p=length(t)^(1:n)),T)


                                              Try it online!



                                              Input and output are vectors of characters. All possible outputs have equal probability.



                                              Explanation (ungolfed version):



                                              s<-scan(,"")                         # takes input as vector of characters
                                              n<-length(s)
                                              t<-unique(s)
                                              sample(t, # sample uniformly at random from the list of unique characters
                                              sample(n,p=length(t)^(1:n)), # with length k in 1..n chosen randomly such that P[k] is proportional to length(t)^k
                                              T) # the sampling is with replacement






                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited 5 hours ago

























                                              answered 5 hours ago









                                              Robin RyderRobin Ryder

                                              5217




                                              5217























                                                  0












                                                  $begingroup$

                                                  T-SQL, 233 bytes



                                                  DECLARE @ varchar(max)='abcd';

                                                  WITH C as(SELECT DISTINCT substring(@,number+1,1)x FROM spt_values
                                                  WHERE'P'=type and len(@)>number),D as(SELECT x,x y FROM c UNION ALL
                                                  SELECT C.x,D.y+D.x FROM C JOIN D ON len(y)<len(@))SELECT
                                                  top 1y FROM D GROUP BY y ORDER BY newid()


                                                  Note the online version will always give the same result unlike MS-SQL Studio Management. This is because newid() always returns the same value in the online testing. This should work in Studio Management.



                                                  Try it online ungolfed






                                                  share|improve this answer









                                                  $endgroup$


















                                                    0












                                                    $begingroup$

                                                    T-SQL, 233 bytes



                                                    DECLARE @ varchar(max)='abcd';

                                                    WITH C as(SELECT DISTINCT substring(@,number+1,1)x FROM spt_values
                                                    WHERE'P'=type and len(@)>number),D as(SELECT x,x y FROM c UNION ALL
                                                    SELECT C.x,D.y+D.x FROM C JOIN D ON len(y)<len(@))SELECT
                                                    top 1y FROM D GROUP BY y ORDER BY newid()


                                                    Note the online version will always give the same result unlike MS-SQL Studio Management. This is because newid() always returns the same value in the online testing. This should work in Studio Management.



                                                    Try it online ungolfed






                                                    share|improve this answer









                                                    $endgroup$
















                                                      0












                                                      0








                                                      0





                                                      $begingroup$

                                                      T-SQL, 233 bytes



                                                      DECLARE @ varchar(max)='abcd';

                                                      WITH C as(SELECT DISTINCT substring(@,number+1,1)x FROM spt_values
                                                      WHERE'P'=type and len(@)>number),D as(SELECT x,x y FROM c UNION ALL
                                                      SELECT C.x,D.y+D.x FROM C JOIN D ON len(y)<len(@))SELECT
                                                      top 1y FROM D GROUP BY y ORDER BY newid()


                                                      Note the online version will always give the same result unlike MS-SQL Studio Management. This is because newid() always returns the same value in the online testing. This should work in Studio Management.



                                                      Try it online ungolfed






                                                      share|improve this answer









                                                      $endgroup$



                                                      T-SQL, 233 bytes



                                                      DECLARE @ varchar(max)='abcd';

                                                      WITH C as(SELECT DISTINCT substring(@,number+1,1)x FROM spt_values
                                                      WHERE'P'=type and len(@)>number),D as(SELECT x,x y FROM c UNION ALL
                                                      SELECT C.x,D.y+D.x FROM C JOIN D ON len(y)<len(@))SELECT
                                                      top 1y FROM D GROUP BY y ORDER BY newid()


                                                      Note the online version will always give the same result unlike MS-SQL Studio Management. This is because newid() always returns the same value in the online testing. This should work in Studio Management.



                                                      Try it online ungolfed







                                                      share|improve this answer












                                                      share|improve this answer



                                                      share|improve this answer










                                                      answered 3 hours ago









                                                      t-clausen.dkt-clausen.dk

                                                      2,074314




                                                      2,074314























                                                          0












                                                          $begingroup$


                                                          Charcoal, 34 bytes



                                                          ≔Φθ⁼κ⌕θιη≔⊕‽ΣEθXLη⊕κζWζ«§ηζ≔÷⊖ζLηζ


                                                          Try it online! Link is to verbose version of code. Explanation:



                                                          ≔Φθ⁼κ⌕θιη


                                                          Extract the unique characters of the input. Let's call the number of unique characters n.



                                                          ≔⊕‽ΣEθXLη⊕κζ


                                                          Calculate the number of combinations for each possible length and take the sum. Then, pick a random number between 1 and this number (inclusive). This ensures that all combinations are equally likely (within the accuracy of the random number generator).



                                                          Wζ«§ηζ≔÷⊖ζLηζ


                                                          Convert the number into bijective base n, using the unique characters as the digits.






                                                          share|improve this answer









                                                          $endgroup$


















                                                            0












                                                            $begingroup$


                                                            Charcoal, 34 bytes



                                                            ≔Φθ⁼κ⌕θιη≔⊕‽ΣEθXLη⊕κζWζ«§ηζ≔÷⊖ζLηζ


                                                            Try it online! Link is to verbose version of code. Explanation:



                                                            ≔Φθ⁼κ⌕θιη


                                                            Extract the unique characters of the input. Let's call the number of unique characters n.



                                                            ≔⊕‽ΣEθXLη⊕κζ


                                                            Calculate the number of combinations for each possible length and take the sum. Then, pick a random number between 1 and this number (inclusive). This ensures that all combinations are equally likely (within the accuracy of the random number generator).



                                                            Wζ«§ηζ≔÷⊖ζLηζ


                                                            Convert the number into bijective base n, using the unique characters as the digits.






                                                            share|improve this answer









                                                            $endgroup$
















                                                              0












                                                              0








                                                              0





                                                              $begingroup$


                                                              Charcoal, 34 bytes



                                                              ≔Φθ⁼κ⌕θιη≔⊕‽ΣEθXLη⊕κζWζ«§ηζ≔÷⊖ζLηζ


                                                              Try it online! Link is to verbose version of code. Explanation:



                                                              ≔Φθ⁼κ⌕θιη


                                                              Extract the unique characters of the input. Let's call the number of unique characters n.



                                                              ≔⊕‽ΣEθXLη⊕κζ


                                                              Calculate the number of combinations for each possible length and take the sum. Then, pick a random number between 1 and this number (inclusive). This ensures that all combinations are equally likely (within the accuracy of the random number generator).



                                                              Wζ«§ηζ≔÷⊖ζLηζ


                                                              Convert the number into bijective base n, using the unique characters as the digits.






                                                              share|improve this answer









                                                              $endgroup$




                                                              Charcoal, 34 bytes



                                                              ≔Φθ⁼κ⌕θιη≔⊕‽ΣEθXLη⊕κζWζ«§ηζ≔÷⊖ζLηζ


                                                              Try it online! Link is to verbose version of code. Explanation:



                                                              ≔Φθ⁼κ⌕θιη


                                                              Extract the unique characters of the input. Let's call the number of unique characters n.



                                                              ≔⊕‽ΣEθXLη⊕κζ


                                                              Calculate the number of combinations for each possible length and take the sum. Then, pick a random number between 1 and this number (inclusive). This ensures that all combinations are equally likely (within the accuracy of the random number generator).



                                                              Wζ«§ηζ≔÷⊖ζLηζ


                                                              Convert the number into bijective base n, using the unique characters as the digits.







                                                              share|improve this answer












                                                              share|improve this answer



                                                              share|improve this answer










                                                              answered 3 hours ago









                                                              NeilNeil

                                                              82.5k745179




                                                              82.5k745179























                                                                  0












                                                                  $begingroup$


                                                                  Wolfram Language (Mathematica), 41 bytes



                                                                  ""<>#&@*RandomChoice@*Subsets@*Characters


                                                                  Try it online!






                                                                  share|improve this answer









                                                                  $endgroup$


















                                                                    0












                                                                    $begingroup$


                                                                    Wolfram Language (Mathematica), 41 bytes



                                                                    ""<>#&@*RandomChoice@*Subsets@*Characters


                                                                    Try it online!






                                                                    share|improve this answer









                                                                    $endgroup$
















                                                                      0












                                                                      0








                                                                      0





                                                                      $begingroup$


                                                                      Wolfram Language (Mathematica), 41 bytes



                                                                      ""<>#&@*RandomChoice@*Subsets@*Characters


                                                                      Try it online!






                                                                      share|improve this answer









                                                                      $endgroup$




                                                                      Wolfram Language (Mathematica), 41 bytes



                                                                      ""<>#&@*RandomChoice@*Subsets@*Characters


                                                                      Try it online!







                                                                      share|improve this answer












                                                                      share|improve this answer



                                                                      share|improve this answer










                                                                      answered 2 hours ago









                                                                      attinatattinat

                                                                      4697




                                                                      4697























                                                                          0












                                                                          $begingroup$


                                                                          MATLAB / Octave, 110 bytes



                                                                          Choose a random permutation of a subset of the input letters (with repetitions), whose random length is based on the probability of generating a word with that length.





                                                                          @(a)a(randi(numel(a),[find(cumsum(numel(a).^[1:numel(a)])>=randi(sum(numel(a).^[1:numel(a)])),1,'first'),1]));


                                                                          Try it online!






                                                                          share|improve this answer









                                                                          $endgroup$


















                                                                            0












                                                                            $begingroup$


                                                                            MATLAB / Octave, 110 bytes



                                                                            Choose a random permutation of a subset of the input letters (with repetitions), whose random length is based on the probability of generating a word with that length.





                                                                            @(a)a(randi(numel(a),[find(cumsum(numel(a).^[1:numel(a)])>=randi(sum(numel(a).^[1:numel(a)])),1,'first'),1]));


                                                                            Try it online!






                                                                            share|improve this answer









                                                                            $endgroup$
















                                                                              0












                                                                              0








                                                                              0





                                                                              $begingroup$


                                                                              MATLAB / Octave, 110 bytes



                                                                              Choose a random permutation of a subset of the input letters (with repetitions), whose random length is based on the probability of generating a word with that length.





                                                                              @(a)a(randi(numel(a),[find(cumsum(numel(a).^[1:numel(a)])>=randi(sum(numel(a).^[1:numel(a)])),1,'first'),1]));


                                                                              Try it online!






                                                                              share|improve this answer









                                                                              $endgroup$




                                                                              MATLAB / Octave, 110 bytes



                                                                              Choose a random permutation of a subset of the input letters (with repetitions), whose random length is based on the probability of generating a word with that length.





                                                                              @(a)a(randi(numel(a),[find(cumsum(numel(a).^[1:numel(a)])>=randi(sum(numel(a).^[1:numel(a)])),1,'first'),1]));


                                                                              Try it online!







                                                                              share|improve this answer












                                                                              share|improve this answer



                                                                              share|improve this answer










                                                                              answered 26 mins ago









                                                                              PieCotPieCot

                                                                              97959




                                                                              97959






















                                                                                  Flog Edoc is a new contributor. Be nice, and check out our Code of Conduct.










                                                                                  draft saved

                                                                                  draft discarded


















                                                                                  Flog Edoc is a new contributor. Be nice, and check out our Code of Conduct.













                                                                                  Flog Edoc is a new contributor. Be nice, and check out our Code of Conduct.












                                                                                  Flog Edoc is a new contributor. Be nice, and check out our Code of Conduct.
















                                                                                  If this is an answer to a challenge…




                                                                                  • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                                                  • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                                                    Explanations of your answer make it more interesting to read and are very much encouraged.


                                                                                  • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                                                                  More generally…




                                                                                  • …Please make sure to answer the question and provide sufficient detail.


                                                                                  • …Avoid asking for help, clarification or responding to other answers (use comments instead).





                                                                                  draft saved


                                                                                  draft discarded














                                                                                  StackExchange.ready(
                                                                                  function () {
                                                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f182735%2fto-string-or-not-to-string%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

                                                                                  陸軍士官学校卒業生一覧 (日本)

                                                                                  濃尾地震

                                                                                  宮崎県