Thanks guys !

Given that you two come with the same solution must be a proof of truth !

# > teletype : code exchange

**chapelierfou**#283

**glia**#284

sooo

I’m trying to parse out why that would work and the mental wall starts @ this command [quote=", post:282, topic:839"]

P I TOSS

[/quote]

what’s the difference between `TOSS`

and `FLIP`

? why does toss accomplish @chapelierfou’s idea?

is this restricted to two pattern banks or does it hop between all four?

**trickyflemming**#285

FLIP inverts everytime (if 1, then 0… if 0, then 1). TOSS acts like a coin toss and returns 0 or 1 randomly.

**chapelierfou**#288

I’d like to populate a pattern with random 1s or 0s, but i also want to specify how many 1s.

Is there a way to do this ?

**glia**#289

[quote=“chapelierfou, post:288, topic:839”]

specify how many 1s

[/quote]in what sense?

Sounds like you want some sort of conditional statement to check that there are pauses rather than:

1

1

1

1

1

1

1

1

1

1

1

**chapelierfou**#291

Thank you. Unfortunately, tehn, that’s not my goal.

Let’s say i want to generate 8 steps, with always 3 zeros (and thus 5 ones) :

1 0 0 1 0 0 0 1 or 1 1 1 0 0 0 0 0 or 0 1 0 0 1 0 1 0 etc…

The purpose :

i generate 2 random patterns to trigger the 2 inputs of René. I want it random but i want always the same length for the pattern created by René.

**chapelierfou**#292

Maybe…but then, i still have no idea how to count the pauses, and how to store the ‘pause sequence’. That would mean the use of a pattern for this. So i’m not sure.

**sakul**#293

I’m a TT noob and this is untested… and it looks overcomplicating… but maybe something like this?

#1

P.N I

P.L 8

L 0 8 : SCRIPT 2

#2

Z TOSS

X 0

IF GT Y 0 : X Z

Y SUB Y Z

P I X

#I

Y 5

L 0 3 : SCRIPT 1

**chapelierfou**#294

Thanks very much.

I admit i absolutely don’t get your code. But i’ll try on the TT !

**tehn**#295

ah, i see what you’re after.

a simple method you might try:

- fill the pattern with 0’s
- randomly fill positions with 1’s

you may get repeat randoms of course

set X to number of possible 1’s. 8 is length

```
L 0 8 : P I 0
L 0 X : P RAND 8 1
```

**GoneCaving**#296

That doesn’t guarantee X 1s if the rand in the second loop turns up the same number twice.

**sam**#298

You need to shuffle if you want to guarantee that you always have the same number of 1s and 0s.

E.g.

```
L 0 99 : P.INS 0 P.RM RAND 8
```

(you need a newish version of the firmware where `P.RM`

returns the value removed).

**chapelierfou**#299

Makes me think : what about a new operator ‘URN’ like urn in max, to output non equal random numbers ?

**chapelierfou**#300

i guess i don’t have the good version :

‘Move left : P.RM’ is the message TT returns.

**tehn**#301

another method, use P.INS randomly

x = how many 0’s

y = how many 1’s

```
X 3
Y 5
P.L 0
L 0 X : P.INS 0 0
L 0 Y : P.INS RAND P.L 1
```

untested but the idea should work

**chapelierfou**#302

Yeah !

Many thanks this works. For the sake of rightness, the correct script is :

X 3

Y 5

P.L 0

L 1 X : P.INS 0 0

L 1 Y : P.INS RAND P.L 1