To string or not to string












7












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










  • $begingroup$
    @EmbodimentofIgnorance Thanks, fixed.
    $endgroup$
    – Flog Edoc
    yesterday










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






  • 1




    $begingroup$
    @Flog Edoc: (2) There is a real difference between 'will contain at least two distinct characters' and 'all characters will be distinct'. Which do you intend?
    $endgroup$
    – Chas Brown
    21 hours ago






  • 1




    $begingroup$
    do you mean given an *input* of aaab? Can we have examples that aren't isomorphic to each other?
    $endgroup$
    – Jo King
    21 hours ago


















7












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










  • $begingroup$
    @EmbodimentofIgnorance Thanks, fixed.
    $endgroup$
    – Flog Edoc
    yesterday










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






  • 1




    $begingroup$
    @Flog Edoc: (2) There is a real difference between 'will contain at least two distinct characters' and 'all characters will be distinct'. Which do you intend?
    $endgroup$
    – Chas Brown
    21 hours ago






  • 1




    $begingroup$
    do you mean given an *input* of aaab? Can we have examples that aren't isomorphic to each other?
    $endgroup$
    – Jo King
    21 hours ago
















7












7








7





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







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 yesterday









Flog EdocFlog Edoc

413




413




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
    yesterday










  • $begingroup$
    @EmbodimentofIgnorance Thanks, fixed.
    $endgroup$
    – Flog Edoc
    yesterday










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






  • 1




    $begingroup$
    @Flog Edoc: (2) There is a real difference between 'will contain at least two distinct characters' and 'all characters will be distinct'. Which do you intend?
    $endgroup$
    – Chas Brown
    21 hours ago






  • 1




    $begingroup$
    do you mean given an *input* of aaab? Can we have examples that aren't isomorphic to each other?
    $endgroup$
    – Jo King
    21 hours ago




















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










  • $begingroup$
    @EmbodimentofIgnorance Thanks, fixed.
    $endgroup$
    – Flog Edoc
    yesterday










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






  • 1




    $begingroup$
    @Flog Edoc: (2) There is a real difference between 'will contain at least two distinct characters' and 'all characters will be distinct'. Which do you intend?
    $endgroup$
    – Chas Brown
    21 hours ago






  • 1




    $begingroup$
    do you mean given an *input* of aaab? Can we have examples that aren't isomorphic to each other?
    $endgroup$
    – Jo King
    21 hours ago


















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




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












$begingroup$
@EmbodimentofIgnorance Thanks, fixed.
$endgroup$
– Flog Edoc
yesterday




$begingroup$
@EmbodimentofIgnorance Thanks, fixed.
$endgroup$
– Flog Edoc
yesterday












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




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




1




1




$begingroup$
@Flog Edoc: (2) There is a real difference between 'will contain at least two distinct characters' and 'all characters will be distinct'. Which do you intend?
$endgroup$
– Chas Brown
21 hours ago




$begingroup$
@Flog Edoc: (2) There is a real difference between 'will contain at least two distinct characters' and 'all characters will be distinct'. Which do you intend?
$endgroup$
– Chas Brown
21 hours ago




1




1




$begingroup$
do you mean given an *input* of aaab? Can we have examples that aren't isomorphic to each other?
$endgroup$
– Jo King
21 hours ago






$begingroup$
do you mean given an *input* of aaab? Can we have examples that aren't isomorphic to each other?
$endgroup$
– Jo King
21 hours ago












15 Answers
15






active

oldest

votes


















5












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



















4












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


    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$


      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$


        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$





















          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
            yesterday










          • $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
            yesterday






          • 1




            $begingroup$
            9 bytes?
            $endgroup$
            – Shaggy
            yesterday






          • 1




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










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



















          1












          $begingroup$


          Wolfram Language (Mathematica), 41 bytes



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


          Try it online!






          share|improve this answer









          $endgroup$













          • $begingroup$
            Wha is this part? ""<>#&@
            $endgroup$
            – Jonah
            5 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
            yesterday






          • 1




            $begingroup$
            If the op changed the rules that's a pity.
            $endgroup$
            – Natural Number Guy
            15 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
            yesterday





















          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$


            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$


              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$

                T-SQL, 222 bytes



                This creates all combinations of each unique character with recursive sql, then picks a random row from the distinct combinations.



                DECLARE @ varchar(max)='T-SQL';

                WITH C as(SELECT DISTINCT substring(@,number+1,1)x
                FROM spt_values
                WHERE'P'=type and len(@)>number),D
                as(SELECT x y
                FROM c UNION ALL
                SELECT y+x
                FROM C JOIN D
                ON len(y)<len(@))SELECT top 1*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 version






                share|improve this answer











                $endgroup$





















                  0












                  $begingroup$


                  Python 2, 124 bytes





                  lambda s:g(list(set(s)),len(s))
                  from random import*
                  g=lambda s,n:choice(s)+(random()*~-len(s)**(n)>~-len(s)and g(s,n-1)or'')


                  Try it online!



                  A different approach: instead of first constructing a list of all compliant strings and choosing one at random, this approach randomly decides to continue extending the string or stopping.



                  This again has to deal with the exacting input requirements, at a cost of 31 bytes; but the function of interest g takes a list s of characters to be used, and an integer n which is the maximum length of the returned string.



                  As an example, consider the set of characters ['a','b'] and suppose we want to generate random strings of length 1, 2, or 3.



                  Then if we randomly choose 'a' as the starting character, the possible strings which could be returned are:



                  a
                  aa
                  aaa
                  aab
                  ab
                  aba
                  abb


                  shown above in 'tree' form, which is a total of 1 + 2 + 2*2 = 2^0 + 2^1 + 2^2 = 7 strings. So if we generate a string a; then 1/7 of the time we should stop and return 'a', and 6/7 of the time we should add further to the string - then the distribution will be uniform in the way desired.



                  More generally, if n is maximum length of the string and x is the number of characters in the set, then the number of strings starting with some given character is going to be:



                  $$h(n)=sum_{i=0}^{n-1} x^i$$
                  $$h(n)=1+x+x^2+x^3...+x^{n-1}$$



                  For x>1 (guaranteed by OP's rule 'at least two distinct...'), we have:



                  $$h(n)(x-1)=(1+x+x^2+x^3...+x^{n-1})(x-1)=x^n-1$$
                  $$h(n)=frac{x^n-1}{x-1}$$



                  So to decide whether we should continue extending our string, let p be a random number in [0,1); then we should recurse only if any of these equivalent statements are true:



                  $$p>frac{1}{h(n)}$$
                  $$p>frac{x-1}{x^n-1}$$
                  $$p(x^n-1)>x-1$$



                  of which g is the golfed implementation.






                  share|improve this answer









                  $endgroup$





















                    0












                    $begingroup$


                    J, 27 bytes



                    [:(?@#{])@;[:,@{&.>#<@#"{<


                    Try it online!



                    standard formatting



                    [: (?@# { ])@; [: ,@{&.> # <@#"1 _ <


                    explanation



                    Eg, for the string 'abc' we first use #<@#"{< to create:



                    ┌─────┬─────────┬─────────────┐
                    │┌───┐│┌───┬───┐│┌───┬───┬───┐│
                    ││abc│││abc│abc│││abc│abc│abc││
                    │└───┘│└───┴───┘│└───┴───┴───┘│
                    └─────┴─────────┴─────────────┘


                    We then take the cartesian product of each of these {, flatten the results, and finally remove the outer boxing ;.



                    (?@#{])@ takes a random result from that list.



                    Note: TIO will return the same result every time, but in a normal J REPL it will be random.






                    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

























                      15 Answers
                      15






                      active

                      oldest

                      votes








                      15 Answers
                      15






                      active

                      oldest

                      votes









                      active

                      oldest

                      votes






                      active

                      oldest

                      votes









                      5












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
















                      5












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














                      5












                      5








                      5





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

























                      answered yesterday









                      Jonathan AllanJonathan Allan

                      53.7k535173




                      53.7k535173












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


















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
















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




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











                      4












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


















                        4












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
















                          4












                          4








                          4





                          $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 19 hours ago

























                          answered yesterday









                          EmignaEmigna

                          47.4k433144




                          47.4k433144























                              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 yesterday









                                  Unrelated StringUnrelated String

                                  1,571312




                                  1,571312























                                      3












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


















                                        3












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
















                                          3












                                          3








                                          3





                                          $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 19 hours ago

























                                          answered yesterday









                                          Jo KingJo King

                                          26.5k364130




                                          26.5k364130























                                              2












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


















                                                2












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
















                                                  2












                                                  2








                                                  2





                                                  $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 20 hours ago

























                                                  answered 23 hours ago









                                                  Chas BrownChas Brown

                                                  5,1691523




                                                  5,1691523























                                                      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
                                                        yesterday










                                                      • $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
                                                        yesterday






                                                      • 1




                                                        $begingroup$
                                                        9 bytes?
                                                        $endgroup$
                                                        – Shaggy
                                                        yesterday






                                                      • 1




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










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
















                                                      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
                                                        yesterday










                                                      • $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
                                                        yesterday






                                                      • 1




                                                        $begingroup$
                                                        9 bytes?
                                                        $endgroup$
                                                        – Shaggy
                                                        yesterday






                                                      • 1




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










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














                                                      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 yesterday

























                                                      answered yesterday









                                                      Luis felipe De jesus MunozLuis felipe De jesus Munoz

                                                      5,71821671




                                                      5,71821671








                                                      • 1




                                                        $begingroup$
                                                        Does this work for abcd --> ac?
                                                        $endgroup$
                                                        – AdmBorkBork
                                                        yesterday










                                                      • $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
                                                        yesterday






                                                      • 1




                                                        $begingroup$
                                                        9 bytes?
                                                        $endgroup$
                                                        – Shaggy
                                                        yesterday






                                                      • 1




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










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














                                                      • 1




                                                        $begingroup$
                                                        Does this work for abcd --> ac?
                                                        $endgroup$
                                                        – AdmBorkBork
                                                        yesterday










                                                      • $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
                                                        yesterday






                                                      • 1




                                                        $begingroup$
                                                        9 bytes?
                                                        $endgroup$
                                                        – Shaggy
                                                        yesterday






                                                      • 1




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










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








                                                      1




                                                      1




                                                      $begingroup$
                                                      Does this work for abcd --> ac?
                                                      $endgroup$
                                                      – AdmBorkBork
                                                      yesterday




                                                      $begingroup$
                                                      Does this work for abcd --> ac?
                                                      $endgroup$
                                                      – AdmBorkBork
                                                      yesterday












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




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




                                                      1




                                                      1




                                                      $begingroup$
                                                      9 bytes?
                                                      $endgroup$
                                                      – Shaggy
                                                      yesterday




                                                      $begingroup$
                                                      9 bytes?
                                                      $endgroup$
                                                      – Shaggy
                                                      yesterday




                                                      1




                                                      1




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




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












                                                      $begingroup$
                                                      I don't think this is correct anymore
                                                      $endgroup$
                                                      – Jo King
                                                      yesterday




                                                      $begingroup$
                                                      I don't think this is correct anymore
                                                      $endgroup$
                                                      – Jo King
                                                      yesterday











                                                      1












                                                      $begingroup$


                                                      Wolfram Language (Mathematica), 41 bytes



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


                                                      Try it online!






                                                      share|improve this answer









                                                      $endgroup$













                                                      • $begingroup$
                                                        Wha is this part? ""<>#&@
                                                        $endgroup$
                                                        – Jonah
                                                        5 hours ago
















                                                      1












                                                      $begingroup$


                                                      Wolfram Language (Mathematica), 41 bytes



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


                                                      Try it online!






                                                      share|improve this answer









                                                      $endgroup$













                                                      • $begingroup$
                                                        Wha is this part? ""<>#&@
                                                        $endgroup$
                                                        – Jonah
                                                        5 hours ago














                                                      1












                                                      1








                                                      1





                                                      $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 17 hours ago









                                                      attinatattinat

                                                      4797




                                                      4797












                                                      • $begingroup$
                                                        Wha is this part? ""<>#&@
                                                        $endgroup$
                                                        – Jonah
                                                        5 hours ago


















                                                      • $begingroup$
                                                        Wha is this part? ""<>#&@
                                                        $endgroup$
                                                        – Jonah
                                                        5 hours ago
















                                                      $begingroup$
                                                      Wha is this part? ""<>#&@
                                                      $endgroup$
                                                      – Jonah
                                                      5 hours ago




                                                      $begingroup$
                                                      Wha is this part? ""<>#&@
                                                      $endgroup$
                                                      – Jonah
                                                      5 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
                                                        yesterday






                                                      • 1




                                                        $begingroup$
                                                        If the op changed the rules that's a pity.
                                                        $endgroup$
                                                        – Natural Number Guy
                                                        15 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
                                                        yesterday






                                                      • 1




                                                        $begingroup$
                                                        If the op changed the rules that's a pity.
                                                        $endgroup$
                                                        – Natural Number Guy
                                                        15 hours 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 yesterday

























                                                      answered yesterday









                                                      Natural Number GuyNatural Number Guy

                                                      1516




                                                      1516












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






                                                      • 1




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


















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






                                                      • 1




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
















                                                      $begingroup$
                                                      I don't think this is correct anymore
                                                      $endgroup$
                                                      – Jo King
                                                      yesterday




                                                      $begingroup$
                                                      I don't think this is correct anymore
                                                      $endgroup$
                                                      – Jo King
                                                      yesterday




                                                      1




                                                      1




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




                                                      $begingroup$
                                                      If the op changed the rules that's a pity.
                                                      $endgroup$
                                                      – Natural Number Guy
                                                      15 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
                                                        yesterday


















                                                      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
                                                        yesterday
















                                                      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 yesterday









                                                      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
                                                        yesterday




















                                                      • $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
                                                        yesterday


















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






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













                                                      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 19 hours ago

























                                                          answered 20 hours ago









                                                          Robin RyderRobin Ryder

                                                          5317




                                                          5317























                                                              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 17 hours ago









                                                                  NeilNeil

                                                                  82.6k745179




                                                                  82.6k745179























                                                                      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 15 hours ago









                                                                          PieCotPieCot

                                                                          97959




                                                                          97959























                                                                              0












                                                                              $begingroup$

                                                                              T-SQL, 222 bytes



                                                                              This creates all combinations of each unique character with recursive sql, then picks a random row from the distinct combinations.



                                                                              DECLARE @ varchar(max)='T-SQL';

                                                                              WITH C as(SELECT DISTINCT substring(@,number+1,1)x
                                                                              FROM spt_values
                                                                              WHERE'P'=type and len(@)>number),D
                                                                              as(SELECT x y
                                                                              FROM c UNION ALL
                                                                              SELECT y+x
                                                                              FROM C JOIN D
                                                                              ON len(y)<len(@))SELECT top 1*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 version






                                                                              share|improve this answer











                                                                              $endgroup$


















                                                                                0












                                                                                $begingroup$

                                                                                T-SQL, 222 bytes



                                                                                This creates all combinations of each unique character with recursive sql, then picks a random row from the distinct combinations.



                                                                                DECLARE @ varchar(max)='T-SQL';

                                                                                WITH C as(SELECT DISTINCT substring(@,number+1,1)x
                                                                                FROM spt_values
                                                                                WHERE'P'=type and len(@)>number),D
                                                                                as(SELECT x y
                                                                                FROM c UNION ALL
                                                                                SELECT y+x
                                                                                FROM C JOIN D
                                                                                ON len(y)<len(@))SELECT top 1*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 version






                                                                                share|improve this answer











                                                                                $endgroup$
















                                                                                  0












                                                                                  0








                                                                                  0





                                                                                  $begingroup$

                                                                                  T-SQL, 222 bytes



                                                                                  This creates all combinations of each unique character with recursive sql, then picks a random row from the distinct combinations.



                                                                                  DECLARE @ varchar(max)='T-SQL';

                                                                                  WITH C as(SELECT DISTINCT substring(@,number+1,1)x
                                                                                  FROM spt_values
                                                                                  WHERE'P'=type and len(@)>number),D
                                                                                  as(SELECT x y
                                                                                  FROM c UNION ALL
                                                                                  SELECT y+x
                                                                                  FROM C JOIN D
                                                                                  ON len(y)<len(@))SELECT top 1*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 version






                                                                                  share|improve this answer











                                                                                  $endgroup$



                                                                                  T-SQL, 222 bytes



                                                                                  This creates all combinations of each unique character with recursive sql, then picks a random row from the distinct combinations.



                                                                                  DECLARE @ varchar(max)='T-SQL';

                                                                                  WITH C as(SELECT DISTINCT substring(@,number+1,1)x
                                                                                  FROM spt_values
                                                                                  WHERE'P'=type and len(@)>number),D
                                                                                  as(SELECT x y
                                                                                  FROM c UNION ALL
                                                                                  SELECT y+x
                                                                                  FROM C JOIN D
                                                                                  ON len(y)<len(@))SELECT top 1*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 version







                                                                                  share|improve this answer














                                                                                  share|improve this answer



                                                                                  share|improve this answer








                                                                                  edited 8 hours ago

























                                                                                  answered 18 hours ago









                                                                                  t-clausen.dkt-clausen.dk

                                                                                  2,074314




                                                                                  2,074314























                                                                                      0












                                                                                      $begingroup$


                                                                                      Python 2, 124 bytes





                                                                                      lambda s:g(list(set(s)),len(s))
                                                                                      from random import*
                                                                                      g=lambda s,n:choice(s)+(random()*~-len(s)**(n)>~-len(s)and g(s,n-1)or'')


                                                                                      Try it online!



                                                                                      A different approach: instead of first constructing a list of all compliant strings and choosing one at random, this approach randomly decides to continue extending the string or stopping.



                                                                                      This again has to deal with the exacting input requirements, at a cost of 31 bytes; but the function of interest g takes a list s of characters to be used, and an integer n which is the maximum length of the returned string.



                                                                                      As an example, consider the set of characters ['a','b'] and suppose we want to generate random strings of length 1, 2, or 3.



                                                                                      Then if we randomly choose 'a' as the starting character, the possible strings which could be returned are:



                                                                                      a
                                                                                      aa
                                                                                      aaa
                                                                                      aab
                                                                                      ab
                                                                                      aba
                                                                                      abb


                                                                                      shown above in 'tree' form, which is a total of 1 + 2 + 2*2 = 2^0 + 2^1 + 2^2 = 7 strings. So if we generate a string a; then 1/7 of the time we should stop and return 'a', and 6/7 of the time we should add further to the string - then the distribution will be uniform in the way desired.



                                                                                      More generally, if n is maximum length of the string and x is the number of characters in the set, then the number of strings starting with some given character is going to be:



                                                                                      $$h(n)=sum_{i=0}^{n-1} x^i$$
                                                                                      $$h(n)=1+x+x^2+x^3...+x^{n-1}$$



                                                                                      For x>1 (guaranteed by OP's rule 'at least two distinct...'), we have:



                                                                                      $$h(n)(x-1)=(1+x+x^2+x^3...+x^{n-1})(x-1)=x^n-1$$
                                                                                      $$h(n)=frac{x^n-1}{x-1}$$



                                                                                      So to decide whether we should continue extending our string, let p be a random number in [0,1); then we should recurse only if any of these equivalent statements are true:



                                                                                      $$p>frac{1}{h(n)}$$
                                                                                      $$p>frac{x-1}{x^n-1}$$
                                                                                      $$p(x^n-1)>x-1$$



                                                                                      of which g is the golfed implementation.






                                                                                      share|improve this answer









                                                                                      $endgroup$


















                                                                                        0












                                                                                        $begingroup$


                                                                                        Python 2, 124 bytes





                                                                                        lambda s:g(list(set(s)),len(s))
                                                                                        from random import*
                                                                                        g=lambda s,n:choice(s)+(random()*~-len(s)**(n)>~-len(s)and g(s,n-1)or'')


                                                                                        Try it online!



                                                                                        A different approach: instead of first constructing a list of all compliant strings and choosing one at random, this approach randomly decides to continue extending the string or stopping.



                                                                                        This again has to deal with the exacting input requirements, at a cost of 31 bytes; but the function of interest g takes a list s of characters to be used, and an integer n which is the maximum length of the returned string.



                                                                                        As an example, consider the set of characters ['a','b'] and suppose we want to generate random strings of length 1, 2, or 3.



                                                                                        Then if we randomly choose 'a' as the starting character, the possible strings which could be returned are:



                                                                                        a
                                                                                        aa
                                                                                        aaa
                                                                                        aab
                                                                                        ab
                                                                                        aba
                                                                                        abb


                                                                                        shown above in 'tree' form, which is a total of 1 + 2 + 2*2 = 2^0 + 2^1 + 2^2 = 7 strings. So if we generate a string a; then 1/7 of the time we should stop and return 'a', and 6/7 of the time we should add further to the string - then the distribution will be uniform in the way desired.



                                                                                        More generally, if n is maximum length of the string and x is the number of characters in the set, then the number of strings starting with some given character is going to be:



                                                                                        $$h(n)=sum_{i=0}^{n-1} x^i$$
                                                                                        $$h(n)=1+x+x^2+x^3...+x^{n-1}$$



                                                                                        For x>1 (guaranteed by OP's rule 'at least two distinct...'), we have:



                                                                                        $$h(n)(x-1)=(1+x+x^2+x^3...+x^{n-1})(x-1)=x^n-1$$
                                                                                        $$h(n)=frac{x^n-1}{x-1}$$



                                                                                        So to decide whether we should continue extending our string, let p be a random number in [0,1); then we should recurse only if any of these equivalent statements are true:



                                                                                        $$p>frac{1}{h(n)}$$
                                                                                        $$p>frac{x-1}{x^n-1}$$
                                                                                        $$p(x^n-1)>x-1$$



                                                                                        of which g is the golfed implementation.






                                                                                        share|improve this answer









                                                                                        $endgroup$
















                                                                                          0












                                                                                          0








                                                                                          0





                                                                                          $begingroup$


                                                                                          Python 2, 124 bytes





                                                                                          lambda s:g(list(set(s)),len(s))
                                                                                          from random import*
                                                                                          g=lambda s,n:choice(s)+(random()*~-len(s)**(n)>~-len(s)and g(s,n-1)or'')


                                                                                          Try it online!



                                                                                          A different approach: instead of first constructing a list of all compliant strings and choosing one at random, this approach randomly decides to continue extending the string or stopping.



                                                                                          This again has to deal with the exacting input requirements, at a cost of 31 bytes; but the function of interest g takes a list s of characters to be used, and an integer n which is the maximum length of the returned string.



                                                                                          As an example, consider the set of characters ['a','b'] and suppose we want to generate random strings of length 1, 2, or 3.



                                                                                          Then if we randomly choose 'a' as the starting character, the possible strings which could be returned are:



                                                                                          a
                                                                                          aa
                                                                                          aaa
                                                                                          aab
                                                                                          ab
                                                                                          aba
                                                                                          abb


                                                                                          shown above in 'tree' form, which is a total of 1 + 2 + 2*2 = 2^0 + 2^1 + 2^2 = 7 strings. So if we generate a string a; then 1/7 of the time we should stop and return 'a', and 6/7 of the time we should add further to the string - then the distribution will be uniform in the way desired.



                                                                                          More generally, if n is maximum length of the string and x is the number of characters in the set, then the number of strings starting with some given character is going to be:



                                                                                          $$h(n)=sum_{i=0}^{n-1} x^i$$
                                                                                          $$h(n)=1+x+x^2+x^3...+x^{n-1}$$



                                                                                          For x>1 (guaranteed by OP's rule 'at least two distinct...'), we have:



                                                                                          $$h(n)(x-1)=(1+x+x^2+x^3...+x^{n-1})(x-1)=x^n-1$$
                                                                                          $$h(n)=frac{x^n-1}{x-1}$$



                                                                                          So to decide whether we should continue extending our string, let p be a random number in [0,1); then we should recurse only if any of these equivalent statements are true:



                                                                                          $$p>frac{1}{h(n)}$$
                                                                                          $$p>frac{x-1}{x^n-1}$$
                                                                                          $$p(x^n-1)>x-1$$



                                                                                          of which g is the golfed implementation.






                                                                                          share|improve this answer









                                                                                          $endgroup$




                                                                                          Python 2, 124 bytes





                                                                                          lambda s:g(list(set(s)),len(s))
                                                                                          from random import*
                                                                                          g=lambda s,n:choice(s)+(random()*~-len(s)**(n)>~-len(s)and g(s,n-1)or'')


                                                                                          Try it online!



                                                                                          A different approach: instead of first constructing a list of all compliant strings and choosing one at random, this approach randomly decides to continue extending the string or stopping.



                                                                                          This again has to deal with the exacting input requirements, at a cost of 31 bytes; but the function of interest g takes a list s of characters to be used, and an integer n which is the maximum length of the returned string.



                                                                                          As an example, consider the set of characters ['a','b'] and suppose we want to generate random strings of length 1, 2, or 3.



                                                                                          Then if we randomly choose 'a' as the starting character, the possible strings which could be returned are:



                                                                                          a
                                                                                          aa
                                                                                          aaa
                                                                                          aab
                                                                                          ab
                                                                                          aba
                                                                                          abb


                                                                                          shown above in 'tree' form, which is a total of 1 + 2 + 2*2 = 2^0 + 2^1 + 2^2 = 7 strings. So if we generate a string a; then 1/7 of the time we should stop and return 'a', and 6/7 of the time we should add further to the string - then the distribution will be uniform in the way desired.



                                                                                          More generally, if n is maximum length of the string and x is the number of characters in the set, then the number of strings starting with some given character is going to be:



                                                                                          $$h(n)=sum_{i=0}^{n-1} x^i$$
                                                                                          $$h(n)=1+x+x^2+x^3...+x^{n-1}$$



                                                                                          For x>1 (guaranteed by OP's rule 'at least two distinct...'), we have:



                                                                                          $$h(n)(x-1)=(1+x+x^2+x^3...+x^{n-1})(x-1)=x^n-1$$
                                                                                          $$h(n)=frac{x^n-1}{x-1}$$



                                                                                          So to decide whether we should continue extending our string, let p be a random number in [0,1); then we should recurse only if any of these equivalent statements are true:



                                                                                          $$p>frac{1}{h(n)}$$
                                                                                          $$p>frac{x-1}{x^n-1}$$
                                                                                          $$p(x^n-1)>x-1$$



                                                                                          of which g is the golfed implementation.







                                                                                          share|improve this answer












                                                                                          share|improve this answer



                                                                                          share|improve this answer










                                                                                          answered 6 hours ago









                                                                                          Chas BrownChas Brown

                                                                                          5,1691523




                                                                                          5,1691523























                                                                                              0












                                                                                              $begingroup$


                                                                                              J, 27 bytes



                                                                                              [:(?@#{])@;[:,@{&.>#<@#"{<


                                                                                              Try it online!



                                                                                              standard formatting



                                                                                              [: (?@# { ])@; [: ,@{&.> # <@#"1 _ <


                                                                                              explanation



                                                                                              Eg, for the string 'abc' we first use #<@#"{< to create:



                                                                                              ┌─────┬─────────┬─────────────┐
                                                                                              │┌───┐│┌───┬───┐│┌───┬───┬───┐│
                                                                                              ││abc│││abc│abc│││abc│abc│abc││
                                                                                              │└───┘│└───┴───┘│└───┴───┴───┘│
                                                                                              └─────┴─────────┴─────────────┘


                                                                                              We then take the cartesian product of each of these {, flatten the results, and finally remove the outer boxing ;.



                                                                                              (?@#{])@ takes a random result from that list.



                                                                                              Note: TIO will return the same result every time, but in a normal J REPL it will be random.






                                                                                              share|improve this answer











                                                                                              $endgroup$


















                                                                                                0












                                                                                                $begingroup$


                                                                                                J, 27 bytes



                                                                                                [:(?@#{])@;[:,@{&.>#<@#"{<


                                                                                                Try it online!



                                                                                                standard formatting



                                                                                                [: (?@# { ])@; [: ,@{&.> # <@#"1 _ <


                                                                                                explanation



                                                                                                Eg, for the string 'abc' we first use #<@#"{< to create:



                                                                                                ┌─────┬─────────┬─────────────┐
                                                                                                │┌───┐│┌───┬───┐│┌───┬───┬───┐│
                                                                                                ││abc│││abc│abc│││abc│abc│abc││
                                                                                                │└───┘│└───┴───┘│└───┴───┴───┘│
                                                                                                └─────┴─────────┴─────────────┘


                                                                                                We then take the cartesian product of each of these {, flatten the results, and finally remove the outer boxing ;.



                                                                                                (?@#{])@ takes a random result from that list.



                                                                                                Note: TIO will return the same result every time, but in a normal J REPL it will be random.






                                                                                                share|improve this answer











                                                                                                $endgroup$
















                                                                                                  0












                                                                                                  0








                                                                                                  0





                                                                                                  $begingroup$


                                                                                                  J, 27 bytes



                                                                                                  [:(?@#{])@;[:,@{&.>#<@#"{<


                                                                                                  Try it online!



                                                                                                  standard formatting



                                                                                                  [: (?@# { ])@; [: ,@{&.> # <@#"1 _ <


                                                                                                  explanation



                                                                                                  Eg, for the string 'abc' we first use #<@#"{< to create:



                                                                                                  ┌─────┬─────────┬─────────────┐
                                                                                                  │┌───┐│┌───┬───┐│┌───┬───┬───┐│
                                                                                                  ││abc│││abc│abc│││abc│abc│abc││
                                                                                                  │└───┘│└───┴───┘│└───┴───┴───┘│
                                                                                                  └─────┴─────────┴─────────────┘


                                                                                                  We then take the cartesian product of each of these {, flatten the results, and finally remove the outer boxing ;.



                                                                                                  (?@#{])@ takes a random result from that list.



                                                                                                  Note: TIO will return the same result every time, but in a normal J REPL it will be random.






                                                                                                  share|improve this answer











                                                                                                  $endgroup$




                                                                                                  J, 27 bytes



                                                                                                  [:(?@#{])@;[:,@{&.>#<@#"{<


                                                                                                  Try it online!



                                                                                                  standard formatting



                                                                                                  [: (?@# { ])@; [: ,@{&.> # <@#"1 _ <


                                                                                                  explanation



                                                                                                  Eg, for the string 'abc' we first use #<@#"{< to create:



                                                                                                  ┌─────┬─────────┬─────────────┐
                                                                                                  │┌───┐│┌───┬───┐│┌───┬───┬───┐│
                                                                                                  ││abc│││abc│abc│││abc│abc│abc││
                                                                                                  │└───┘│└───┴───┘│└───┴───┴───┘│
                                                                                                  └─────┴─────────┴─────────────┘


                                                                                                  We then take the cartesian product of each of these {, flatten the results, and finally remove the outer boxing ;.



                                                                                                  (?@#{])@ takes a random result from that list.



                                                                                                  Note: TIO will return the same result every time, but in a normal J REPL it will be random.







                                                                                                  share|improve this answer














                                                                                                  share|improve this answer



                                                                                                  share|improve this answer








                                                                                                  edited 6 hours ago

























                                                                                                  answered 8 hours ago









                                                                                                  JonahJonah

                                                                                                  2,5711017




                                                                                                  2,5711017






















                                                                                                      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

                                                                                                      Knooppunt Holsloot

                                                                                                      Altaar (religie)

                                                                                                      Gregoriusmis