I was trying with String Functions and I viewing any posts and have no results
I want to know
1.- From
cromo33 = Table[RandomInteger[], {i, 1, 33}]
cromo33
that gives {1,0,1,1,1,0,1,......,1,0,0} , alist of 33 elements
How can you obtain "1011101.....100" ?
2.- From
IntegerString[RandomInteger[8], 2] // InputForm
that gives 101 (a little add-on... ¿how can I force this to obtain 4 digits in any random number?)
How can you obtain a list {1,0,1} ?
Answer
There are built-in functions to play:
NumberForm[FromDigits@RandomInteger[1, 5], 6, NumberPadding -> "0"]
"0011101"
Or very straightforward approach:
1
RandomInteger[1, 5]
PadLeft[%, 7]
ToString /@ %
StringJoin@%
{0, 1, 0, 1, 0}
{0, 0, 0, 1, 0, 1, 0}
{"0", "0", "0", "1", "0", "1", "0"}
"0001010"
2
IntegerString[RandomInteger[8], 2]
Characters@%
PadLeft[%, 4]
ToExpression@%
"101"
{"1", "0", "1"}
{0, "1", "0", "1"}
{0, 1, 0, 1}
Comments
Post a Comment