<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with random() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=random%28%29</link>
      <pubDate>Sun, 08 Aug 2021 19:10:15 +0000</pubDate>
         <description>Tagged with random() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedrandom%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>Beginner Question: How to Build Sound Player that Creates &amp; Plays Random mp3 Playlist?</title>
      <link>https://forum.processing.org/two/discussion/27620/beginner-question-how-to-build-sound-player-that-creates-plays-random-mp3-playlist</link>
      <pubDate>Sun, 01 Apr 2018 20:55:01 +0000</pubDate>
      <dc:creator>sammy</dc:creator>
      <guid isPermaLink="false">27620@/two/discussions</guid>
      <description><![CDATA[<p>Hello! I'm a musician and <em>complete</em> programming noob. Thanks for making this space so welcoming! I'm trying to wrap my head around a sound project I'm working on. I welcome any direction you can provide.</p>

<p>Basically, I'm trying to create web-based sound player that, when clicked, plays a randomized playlist of sound files. I'm imagining that to create this, I'll use a variant on this p5 Load and Play Sound code (<a rel="nofollow" href="https://p5js.org/examples/sound-load-and-play-sound.html" title="Load and Play Sound">link</a>). Other stuff I'll need, in addition to the components in the example, (I'm guessing) will be:</p>

<ul>
<li><p>A set of mp3s in a folder.</p></li>
<li><p>Calling these mp3s somehow, maybe with <code>random()</code>.</p></li>
<li><p>Either triggering each new mp3 from the end of the previous mp3, or assembling them in order when the player is clicked.</p></li>
</ul>

<p>Does that sound right? Any general or specific recommendations about how to make this happen?</p>

<p>Thanks a lot!</p>
]]></description>
   </item>
   <item>
      <title>Random images speed to change varyingly, not accordingly to frameRate.</title>
      <link>https://forum.processing.org/two/discussion/25967/random-images-speed-to-change-varyingly-not-accordingly-to-framerate</link>
      <pubDate>Mon, 15 Jan 2018 09:41:55 +0000</pubDate>
      <dc:creator>unknownplayer</dc:creator>
      <guid isPermaLink="false">25967@/two/discussions</guid>
      <description><![CDATA[<p>Hello, sorry if the question title is a bit off. Here is my code which basically loads 200 random images from my folder and makes them pour like the matrix code :), they all change randomly within as well.  But as you can see from the loop in draw they all change at the same time according to the frameRate but I want them to change randomly in varying speeds, sometimes even stop too. I feel like this can be managed via frameCount but couldn't figure out how exactly - did some research on it as well but couldn't find any. Thank you in advance.</p>

<pre><code>    PImage[] myImageArray = new PImage[200];
    float px;
    float py; 
    float pz;

    void setup() {

      size(1920, 1080,P3D);
      frameRate(15);
      background(0);

      for (int i = 0; i &lt; myImageArray.length; ++i) {
        (myImageArray[i] = loadImage("frag_" + i + ".jpg")).resize(0, 45);
      }
    }

    void draw() {

      background(0);
      pushMatrix();
      translate(px, py, pz);
      py+=5; // Glitch skip
      //pz-=5; // For zoom out
      for (int i=-2000; i&lt;width; i+=125) {
        for (int j=-3000; j&lt;3000; j+=95) {
        //for (int j=0; j&lt;3000; j+=25) { // For glitch effect
         imageMode(CENTER);
         image(myImageArray[(int)random(200)], i, j);
         }
      } 
      popMatrix(); 
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Random Color random(255) or random(256)?</title>
      <link>https://forum.processing.org/two/discussion/26102/random-color-random-255-or-random-256</link>
      <pubDate>Wed, 24 Jan 2018 16:25:34 +0000</pubDate>
      <dc:creator>strauss</dc:creator>
      <guid isPermaLink="false">26102@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to make a random color in processing. Online I found two solutions.</p>

<p>SOLUTION_A:  <strong>color c=color(int(random(255)),int(random(255)),int(random(255)));</strong></p>

<p>SOLUTION_B: <strong>color c=color(int(random(256)),int(random(256)),int(random(256)));</strong></p>

<p>The difference being that SOLUTION_A uses random(255) and SOLUTION_B uses random(256)</p>

<p><strong>What solution is correct?</strong></p>

<p><em>I think SOLUTION_B correct but I'm not sure.</em></p>
]]></description>
   </item>
   <item>
      <title>Unique random number for elements in array</title>
      <link>https://forum.processing.org/two/discussion/7696/unique-random-number-for-elements-in-array</link>
      <pubDate>Sun, 19 Oct 2014 14:58:55 +0000</pubDate>
      <dc:creator>tutoki</dc:creator>
      <guid isPermaLink="false">7696@/two/discussions</guid>
      <description><![CDATA[<p>Unique random number for elements in array</p>

<p>I have to create an array of numbers (five element) that have to be unique</p>

<pre><code>int[] numbers = new int[5];
for (int h = 0; h &lt;= 4; h++)
{
 // how to check this random number is unique
    numbers[h] = (int)random(0, 7);
}
printArray(numbers);
</code></pre>

<p>Any clue ?
Thank in advance
SALUD...</p>
]]></description>
   </item>
   <item>
      <title>How to use a generated number once, before going on to the next number?</title>
      <link>https://forum.processing.org/two/discussion/22899/how-to-use-a-generated-number-once-before-going-on-to-the-next-number</link>
      <pubDate>Sat, 03 Jun 2017 13:42:51 +0000</pubDate>
      <dc:creator>Salma4</dc:creator>
      <guid isPermaLink="false">22899@/two/discussions</guid>
      <description><![CDATA[<p>I have managed to generate random numbers between 0 and 100, however, the program keeps on going with this function. It doesn't just pick one random number as needed, it just keeps on going with a list of different numbers. How do I change this?</p>

<p>(Sorry, noob with code here)</p>
]]></description>
   </item>
   <item>
      <title>Random spot of an array</title>
      <link>https://forum.processing.org/two/discussion/22573/random-spot-of-an-array</link>
      <pubDate>Sat, 13 May 2017 20:15:09 +0000</pubDate>
      <dc:creator>Lukas</dc:creator>
      <guid isPermaLink="false">22573@/two/discussions</guid>
      <description><![CDATA[<p>So I have an array and need a random spot of it.
The problem is, that I need that spot twice so I can't really use</p>

<pre><code>random(ArrayName);
random(ArrayName);
</code></pre>

<p>because I would get two different spots.
I also can't do</p>

<pre><code>    var rand = int(random(0, 4));
    arrayName[this.rand];
</code></pre>

<p>because the syntax doesn't allow it.
I hope you get my point and someone knows an answer.
Thanks in advance.</p>
]]></description>
   </item>
   <item>
      <title>Get stroke value in p5.js</title>
      <link>https://forum.processing.org/two/discussion/22482/get-stroke-value-in-p5-js</link>
      <pubDate>Tue, 09 May 2017 13:58:45 +0000</pubDate>
      <dc:creator>Tushar</dc:creator>
      <guid isPermaLink="false">22482@/two/discussions</guid>
      <description><![CDATA[<p>My code is something like this:</p>

<pre><code>stroke(random([0,255]),random([0,255]),random([0,255]));
</code></pre>

<p>Now, what I want is to eliminate the possibility of getting stroke(0,0,0) here. I know I can do this with a condition, something like:</p>

<pre><code>if (Stroke.value() == [0,0,0]){...}
</code></pre>

<p>but that doesn't exist.</p>

<p>Can someone tell me the correct way to do this?</p>
]]></description>
   </item>
   <item>
      <title>retrieving elements from a list randomly</title>
      <link>https://forum.processing.org/two/discussion/20529/retrieving-elements-from-a-list-randomly</link>
      <pubDate>Sun, 29 Jan 2017 10:09:40 +0000</pubDate>
      <dc:creator>Chrisir</dc:creator>
      <guid isPermaLink="false">20529@/two/discussions</guid>
      <description><![CDATA[<p>hello all,</p>

<p>obviously an old problem. It occurs in different forms.</p>

<p>E.g. in a scrabble game we have to hand out letters to the players. But they are not distributed evenly over the Alphabet, so there are not as many Qs than Es in the game (reflecting the distribution of letters in normal English texts).</p>

<p>Let's therefore assume, I make a char array, where this distribution is reflected, so it's</p>

<p><code>EEEEEEEEEQAAAAAAMMOO</code> or so.</p>

<p>Now retrieving elements from this list randomly:</p>

<p>When I retrieved a letter I can't retrieve it again. I can replace it with a character that is a stop sign like #.</p>

<p><code>EEEEE#EEEQAAAAAAMMOO</code></p>

<p>But then when retrieving a letter later in the game, most slots hold #-signs.</p>

<p><code>##E################O#</code></p>

<p>So a typical random like</p>

<p><code>randomNumberIndex = int(random(listOfLetters.length()));</code> would most times fail, so I would have to repeat it until hitting a letter. Bad.</p>

<p>But what is the most efficient way of solving this? An ArrayList and then shorten the ArrayList ?</p>

<p>Thanks!</p>

<p>Best, Chrisir   ;-)</p>
]]></description>
   </item>
   <item>
      <title>18645: Uncaught TypeError: Cannot read property 'elt' of undefined</title>
      <link>https://forum.processing.org/two/discussion/21997/18645-uncaught-typeerror-cannot-read-property-elt-of-undefined</link>
      <pubDate>Fri, 14 Apr 2017 18:01:38 +0000</pubDate>
      <dc:creator>Lukas</dc:creator>
      <guid isPermaLink="false">21997@/two/discussions</guid>
      <description><![CDATA[<p>So I'm writing some code which has to do with the use of images.</p>

<pre><code>var img = [];
var imgs = [];

function preload() {
  img[0] = loadImage("images/egg1.jpg");
  img[1] = loadImage("images/egg2.jpg");
  img[2] = loadImage("images/egg3.jpg");
}

var i_ = new Imgs(circles[n].x, circles[n].y, img[random(0,2)]);
imgs.push(i_);

function Imgs(x_, y_){
  this.x = x_;
  this.y = y_;
  this.img;

  this.update = function(){
    this.img = imgs[random(0,2)];
    image(this.img, this.x, this.y);
  }
}
</code></pre>

<p>So I am trying to display a random Image every time I click on an object.
Therefore I created an object which gets the x and y value and the image which it should display (as an array of preloaded images).
I tried a lot of different versions of this (without creating an object and an array of images) but every time I try to display a random image, this weird error occures: 18645: Uncaught TypeError: Cannot read property 'elt' of undefined.</p>

<p>(I think) the problem is this part: 
<code>img[random(0,2)]</code>
If i write 
<code>img[0]</code>
the image is normally displayed but if I use a random value or a variable, the error message comes up.</p>

<p>I saw this problem in another post but unfortunately the answers didn't help me.
PS: please excuse my bad writing.</p>
]]></description>
   </item>
   <item>
      <title>Static methods</title>
      <link>https://forum.processing.org/two/discussion/21780/static-methods</link>
      <pubDate>Mon, 03 Apr 2017 13:36:18 +0000</pubDate>
      <dc:creator>cygig</dc:creator>
      <guid isPermaLink="false">21780@/two/discussions</guid>
      <description><![CDATA[<pre><code>static class MyNumber{
int no = 0;
static int max= -9999999;
static int min = 9999999;

MyNumber(int n){
  no = n;
  if (no&gt;max){ max = no; }
  if (no&lt;min){min = no; }
}

static void report(){
  println("Min: "+min+", Max: "+max);  
}

static float randomNo(){
  return random(min, max);  

}
</code></pre>

<p>In the above code, I get the error <code>Cannot make a static reference to the non-static method random(float, float) from the type PApplet</code>. Why is that so? I wish to keep a list of min and max numbers for all instances of <code>MyNumber</code>, and hope to operate on those values via a static method.</p>
]]></description>
   </item>
   <item>
      <title>Random function is generating the same numbers</title>
      <link>https://forum.processing.org/two/discussion/21509/random-function-is-generating-the-same-numbers</link>
      <pubDate>Mon, 20 Mar 2017 18:02:36 +0000</pubDate>
      <dc:creator>TPRammus</dc:creator>
      <guid isPermaLink="false">21509@/two/discussions</guid>
      <description><![CDATA[<p>I want to generate <strong>sets of coordinates consisting of X and Y</strong>, but I want every set to be different.
Everytime I restart the program the sets are different to the last time I ran the program but all sets have the same X and the same Y.</p>

<pre><code>void setStars()
{
  int randX = 10, randY = 10;     // the random X and Y coordinates will be saved in here
  boolean genNew = true;    // determines, if we need to regenerate the set of coordiantes
  for (int i = 0; i &lt; starsCount; i++)   // starsCount is the number of sets I want
  {
    while (genNew)    // while the generated X and Y matches an other set
    {
      randX = (int)random(10, windowWidth-10);    // generate the set
      randY = (int)random(10, windowHeight-10);

      genNew = false;
      for (int j = 0; j &lt; starsX.size(); j++)
      {
        if (randX == starsX.get(j) &amp;&amp; randY == starsY.get(j))    // if the generated X and Y matches a set
        {
          genNew = true;         // Generate a new set (basically continue the while loop)
          break;
        }
      }
    }

    starsX.add(randX);     // add the generated random X and Y to the ArrayLists
    starsY.add(randY);
  }
}
</code></pre>

<p>I hope that you will help me solve this problem.</p>

<p>regards, TPRammus</p>

<p><strong>EDIT:
Thank you all! Now I see my error.
I fixed it by adding "genNew = true;" to the beginning of my for(i)-loop.</strong></p>
]]></description>
   </item>
   <item>
      <title>Help to understand and finish my code: GRID with point and random functions, "for" (loop) and space.</title>
      <link>https://forum.processing.org/two/discussion/20896/help-to-understand-and-finish-my-code-grid-with-point-and-random-functions-for-loop-and-space</link>
      <pubDate>Mon, 20 Feb 2017 11:07:24 +0000</pubDate>
      <dc:creator>MirielLind</dc:creator>
      <guid isPermaLink="false">20896@/two/discussions</guid>
      <description><![CDATA[<p>Goodmorning everybody, 
I was trying to use the random() function to create a visually interesting grid ( a number of crossing horizontal and vertical lines) made up of adjacent points (with space between each other) and not by using the line() function. I was trying to use only the loop "for"  but I am having problems on the next step.
This is the start of my code.</p>

<p><code>int verticalNumberLines=20;
int horizontalNumberLines=20;
int space=5;
size(400, 400);
background(#99ff66);
strokeWeight(2);
for (int i=0; i&lt;width; i+=width/verticalNumberLines)
{
  for (int j=0; j&lt;height; j+=space)
  {
    point(i, j);
  }
}
for (int j=0; j&lt;height; j+=height/horizontalNumberLines)
{
  for (int i=0; i&lt;width; i+=space)
  {
    point(i, j);
  }
}</code></p>

<p>this is what I have now</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/046/421T0IYJW0Y2.png" alt="grid 15" title="grid 15" /></p>

<p>and this second gray and orange grid is what I am trying to do, now I am very close and I tried in different ways but I don't understand what I should change, where I should use the random function.Could someone help me, please?!</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/049/MWOHEY0EHMZV.png" alt="16809802_10211470424377501_1726481167_n" title="16809802_10211470424377501_1726481167_n" /></p>
]]></description>
   </item>
   <item>
      <title>Randomly selecting specific numbers</title>
      <link>https://forum.processing.org/two/discussion/19735/randomly-selecting-specific-numbers</link>
      <pubDate>Tue, 13 Dec 2016 21:29:39 +0000</pubDate>
      <dc:creator>Infinitiive</dc:creator>
      <guid isPermaLink="false">19735@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone!</p>

<p>I'm new to processing and coding in general for that matter. I assume this will be a fairly straight forward question for you coding pros.</p>

<p>I have a piece of code with a variable for the x direction of an object. Each time I start the program I would like for that number to be randomly selected to be either 1 or -1, nothing in between. Any idea on how I would do this?</p>

<p>Thanks in advance!</p>
]]></description>
   </item>
   <item>
      <title>how do i specify the minimum and maximum of random();     ?</title>
      <link>https://forum.processing.org/two/discussion/19496/how-do-i-specify-the-minimum-and-maximum-of-random</link>
      <pubDate>Sun, 04 Dec 2016 01:33:21 +0000</pubDate>
      <dc:creator>werdeyo</dc:creator>
      <guid isPermaLink="false">19496@/two/discussions</guid>
      <description><![CDATA[<p>hey guys i cant find the answer to this question so i decided to post it on the forum for help. Thanks!</p>
]]></description>
   </item>
   <item>
      <title>p5.js changing data types (from float into int)</title>
      <link>https://forum.processing.org/two/discussion/18799/p5-js-changing-data-types-from-float-into-int</link>
      <pubDate>Sun, 30 Oct 2016 23:21:06 +0000</pubDate>
      <dc:creator>beccarose</dc:creator>
      <guid isPermaLink="false">18799@/two/discussions</guid>
      <description><![CDATA[<p>Hey!
I've started using p5.js after using processing, and so I am stuck trying to change a float into an int.</p>

<p>I want to get a random integer so I can upload a random image:
<code>// get a random number for image
var imgNum; 
function setup(){
imgNum = random(0, 14);
}</code></p>

<p>How would I go about converting the random number into an int?</p>

<p>thanks!</p>
]]></description>
   </item>
   <item>
      <title>random(-1,1) Processing Bug? Or, coding nuance?</title>
      <link>https://forum.processing.org/two/discussion/18235/random-1-1-processing-bug-or-coding-nuance</link>
      <pubDate>Wed, 21 Sep 2016 18:41:05 +0000</pubDate>
      <dc:creator>goodsignal</dc:creator>
      <guid isPermaLink="false">18235@/two/discussions</guid>
      <description><![CDATA[<p>I'm getting an unbalanced random distribution (heavily negative) from</p>

<p><code>float stepu = random(-1, 1); //red</code></p>

<p>And a balanced random distribution from</p>

<p><code>float stepx = random(3)-1; //blue</code></p>

<p>Shouldn't these two lines be roughly equivalent in results? Red is clearly weighted negative in the comparison code.</p>

<p><img src="http://s17.postimg.org/6yd3zu8in/randomissue.png" alt="" /></p>

<p>Is this a Processing bug? If not, can someone clarify the difference. Or, what I'm doing that's causing slanted results.
Thanks.</p>

<pre lang="processing">
int x,y,u,v; 
void setup(){
  size(200,200);
  stroke(0);
  x = width/2;
  y = height/2;
  u = x;
  v = y;
}
void draw(){
  float stepu = random(-1, 1);
  float stepv = random(-1, 1);
  u += stepu;
  v += stepv;
  stroke(255,0,0);
  point(u,v);

  float stepx = random(3)-1;
  float stepy = random(3)-1;
  x += stepx;
  y += stepy;
  stroke(0,0,255);
  point(x,y);
}
</pre>

<ul>
<li>Processing v3.2.1</li>
<li>Windows 10 64b</li>
</ul>

<p>PS: I did try to search this issue first. The only one I found was <a rel="nofollow" href="https://forum.processing.org/two/discussion/15492/noise-walker-weird-direction-tendency">discussion/15492</a> without a clear answer.</p>
]]></description>
   </item>
   <item>
      <title>Why am I getting these rogue random values?</title>
      <link>https://forum.processing.org/two/discussion/17633/why-am-i-getting-these-rogue-random-values</link>
      <pubDate>Sat, 23 Jul 2016 22:21:14 +0000</pubDate>
      <dc:creator>brooklev</dc:creator>
      <guid isPermaLink="false">17633@/two/discussions</guid>
      <description><![CDATA[<p>Hello Sages,</p>

<p>My Missile Command game is starting to look nice, but in trying to get the bombs to drop at helpful (while still slightly random) angles, I am getting some confusing results.</p>

<p>Basically, I have divided the 800 pixels of my game window into quarters.<br />
Bombs fall from random X positions along the top of the screen:<br />
- A bomb from the far left quarter should be assigned a highly positive X change so that it angles to the right.<br />
- X change of bomb from the center-left quarter: slightly negative to moderately positive<br />
- X change of bomb from the center-right quarter: moderately negative to slightly positive<br />
- X change of bomb from the far right quarter: highly negative</p>

<p>I use <em>bombV</em> to hold the X change:</p>

<pre><code>if (bombX &lt; 200) {
  bombV = random(0, .05);}
else if ((200 &lt;= bombX) &amp;&amp; (bombX &lt; 400)) {
  bombV = random(-.025, .04);}
else if ((400 &lt;= bombX) &amp;&amp; (bombX &lt; 600)) {
  bombV = random(-.04, .025);}
else {
  bombV = random(-.05, 0);}
</code></pre>

<p>(Yes, I am really using variables for the dimensions of the quarters, but 200/400/600 seems clearer now.)</p>

<p>Somehow, the bombs are angling incorrectly. I am getting console values like Bombs 5-9 in a burst of 9 bombs:</p>

<p>Bomb 1 bombX = 517.0 , bombV = 0.030513832<br />
Bomb 2 bombX = 638.0 , bombV = -6.9901906E-4<br />
Bomb 3 bombX = 248.0 , bombV = -0.042253446<br />
Bomb 4 bombX = 41.0 , bombV = 0.014684731<br />
Bomb 5 bombX = 148.0 , bombV = -0.010228617<br />
Bomb 6 bombX = 624.0 , bombV = 0.040641826<br />
Bomb 7 bombX = 16.0 , bombV = -0.021269897<br />
Bomb 8 bombX = 720.0 , bombV = 0.016892198<br />
Bomb 9 bombX = 19.0 , bombV = -0.023663083</p>

<p>I'd love to know what I'm doing wrong. Thanks much for any help!</p>
]]></description>
   </item>
   <item>
      <title>How to randomly select an integer from 2 sets of ranges?</title>
      <link>https://forum.processing.org/two/discussion/17583/how-to-randomly-select-an-integer-from-2-sets-of-ranges</link>
      <pubDate>Tue, 19 Jul 2016 12:52:05 +0000</pubDate>
      <dc:creator>RomiNam</dc:creator>
      <guid isPermaLink="false">17583@/two/discussions</guid>
      <description><![CDATA[<p>Hello! 
I'm very new to processing and I want to randomly select an integer out of 2 sets of ranges.
For my example here, I'm working with colorMode(HSB) and I want the program to select Hue from say 0-50 and 200-255.</p>

<p>This is the code I have at the moment and as you can see, it is randomly selecting the hue value from 50-250 but is there any way I can set it so it selects from 0-50 and 200-250? So it doesn't select any number between 51-199 and 251-255.</p>

<p>Any advice or help would be greatly appreciated!
Thank you!</p>

<pre><code>int amt = 10;

int[] x1 = new int[amt];
int[] x2 = new int[amt];
int[] y1 = new int[amt];
int[] y2 = new int[amt];

color[] c = new color[amt];

color bgcolor;

void setup() {
  size(600,600);
  colorMode(HSB);
  rectMode(CORNERS);
  noStroke();
  bgcolor = color(random(50),100,255);
  background(bgcolor);

  for(int i = 0; i &lt; amt; i++){
    x1[i] = int(random(width)); 
    x2[i] = x1[i] + int(random(80,800));
    y1[i] = int(random(height));
    y2[i] = y1[i] + int(random(50,500));
    c[i] = color(random(50,250),90,255);
  }
}

void draw() {
    for(int i = 0; i &lt; amt; i++){
      fill(c[i]);
      rect(x1[i],y1[i], x2[i], y2[i]);
    }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to make random() only choose integers?</title>
      <link>https://forum.processing.org/two/discussion/16406/how-to-make-random-only-choose-integers</link>
      <pubDate>Tue, 03 May 2016 16:08:08 +0000</pubDate>
      <dc:creator>Oversaftigt</dc:creator>
      <guid isPermaLink="false">16406@/two/discussions</guid>
      <description><![CDATA[<p>Is there a way? If not are there other codes that can do the trick?</p>
]]></description>
   </item>
   <item>
      <title>How to exclude values in a variable and reset the program to start with a single click mouse</title>
      <link>https://forum.processing.org/two/discussion/14883/how-to-exclude-values-in-a-variable-and-reset-the-program-to-start-with-a-single-click-mouse</link>
      <pubDate>Fri, 12 Feb 2016 23:29:05 +0000</pubDate>
      <dc:creator>theomail</dc:creator>
      <guid isPermaLink="false">14883@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I would like to know how to exclude values in a variable when it takes values in a random () function. For example my variable y takes values randomly between 20 and 780 or y = (random (20,780))
However I do not want the variable y takes values between 300 and 400.
Basically I want a function that prohibits y to take value between 300 and 400 but the rest yes.
In addition I also search a function to initialize the program at the beginning when I press my mouse with a simple click. Indeed when I click on run, the program starts on a page 1 and when I finished my program, the program shows me on page 2. So on the page 2 when I click with my mouse, it starts again like at the beginning. If it's possible of course.</p>

<p>Thank you.</p>
]]></description>
   </item>
   <item>
      <title>[Answered] Growing random lines</title>
      <link>https://forum.processing.org/two/discussion/14142/answered-growing-random-lines</link>
      <pubDate>Thu, 24 Dec 2015 23:26:25 +0000</pubDate>
      <dc:creator>Kevzog</dc:creator>
      <guid isPermaLink="false">14142@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone!
I'm trying to make random lines that grows one after another.
I got this far:</p>

<pre><code>int xrand = 300;
int yrand = 300;
int py = 0;
int px = 0;
int x;
int y;

void setup () {
  size (500,500);
  smooth();
}

void draw () {
  if (x&lt;xrand) {
    x = x + 1;
  } else if (x&gt;xrand) {
    x = x - 1;
  } else {
    px = x;
    xrand = (int) random(0,width);
  }
  if (y&lt;yrand) {
    y = y + 1;
  } else if (y&gt;yrand) {
    y = y - 1;
  } else {
    py = y;
    yrand = (int) random(0,height);
  }
  line (px,py,x,y);
}

void mousePressed () {
  println(xrand,yrand,px,py,x,y);
}
</code></pre>

<p>The problem is that when the lines are growing they're drawing "every single step" but i only want the straight line.
Anyone know how to solve it?
Thanks!!</p>
]]></description>
   </item>
   <item>
      <title>How to assign arrays to variables?</title>
      <link>https://forum.processing.org/two/discussion/13886/how-to-assign-arrays-to-variables</link>
      <pubDate>Fri, 11 Dec 2015 02:18:51 +0000</pubDate>
      <dc:creator>cleanass</dc:creator>
      <guid isPermaLink="false">13886@/two/discussions</guid>
      <description><![CDATA[<p>Here I have 1 array with two different iterations of the possible shapes it can create. How can I assign these shapes to variables that I would then cycle through using the random function?</p>

<p>For example, the first shape would be 1, then second shape would be 2 etc. random(1,2,3etc)</p>

<pre><code>  shape[0] = new Cell(4, 0, 35, true);
  shape[1] = new Cell(5, 0, 35, true);

  shape[0] = new Cell(5, 0, 35, true);
  shape[2] = new Cell(5, 1, 35, true);
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to randomly translate a rotating image?</title>
      <link>https://forum.processing.org/two/discussion/13701/how-to-randomly-translate-a-rotating-image</link>
      <pubDate>Mon, 30 Nov 2015 02:24:35 +0000</pubDate>
      <dc:creator>jbarton</dc:creator>
      <guid isPermaLink="false">13701@/two/discussions</guid>
      <description><![CDATA[<p>Hi all,</p>

<p>I'm very new to Processing, and this is my first post! I'm working on a school assignment in which I'm trying to randomly translate rotating images so that when the program runs, they are assigned a random position and rotate in that position for the duration of the program.</p>

<p>I also have other variables that I want to randomize, such as the angle of the images and the speed of the rotations.</p>

<p>Right now when I run the program, any variable that I randomize bounces around the screen, refreshing itself to a new location every frame. I can't seem to figure out how to make the images stay in one location, without pausing the rotations of the images as well.</p>

<p>Here is my code, with currently just the translation of "img1a" improperly randomized. I've included the code for "img1b" as well:</p>

<pre><code>PImage img1a;
PImage img1b;

float rot1a;   // Variable for image rotation
float rot1b;

void setup() {
  size(700, 800, P3D);
  smooth();

   background(255);

  // Load image, initialize variables
  img1a = loadImage("1a.png");
  img1a.resize(300,0);

  img1b = loadImage("1b.png");
  img1b.resize(300,0);

}


void draw() {
  background(255);

  translate(0,150);

  // Image 1a
   pushMatrix();
  background(255);
  translate(random(width),random(height)); // I want to randomize this translate
  rotate(rot1a); 
  rotateY(radians(10)); // I want to randomize this angle
  rotateX(radians(30)); // I want to randomize this angle
  imageMode(CENTER);
  image(img1a,0,0); 
  rot1a += 0.01; // I want to randomize the rotation speed

    popMatrix();


   // Image 1b
    pushMatrix(); 
  translate(350,55); 
  rotate(rot1b); 
  rotateY(radians(35)); 
  rotateX(radians(5)); 
  imageMode(CENTER);
  image(img1b,0,0); 
  rot1b += 0.005;

    popMatrix();

  }
</code></pre>

<p>Eventually, I want the program to loop itself every ten seconds, so that every ten seconds the images have new random variables. That will be the next challenge!</p>

<p>Thank you for your help!</p>
]]></description>
   </item>
   <item>
      <title>Question about the pixels[] array</title>
      <link>https://forum.processing.org/two/discussion/13413/question-about-the-pixels-array</link>
      <pubDate>Thu, 05 Nov 2015 17:20:21 +0000</pubDate>
      <dc:creator>Tngabor</dc:creator>
      <guid isPermaLink="false">13413@/two/discussions</guid>
      <description><![CDATA[<p>In this little program, why does pixels[y * width + x] equate to assign a random color to every pixel? My first reaction was to do pixels[x*y] but that gives a strange result.</p>

<pre><code>void setup() { size(700,700); }
void draw() {
  background(0);
  randomSeed(42);
  loadPixels();
  for (int x = 0; x &lt; width; x++) {
    for (int y = 0; y &lt; height; y++) {
      float randomValue = random(255);
      pixels[y*width + x] = color(randomValue);
    }
  }
  updatePixels();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Monty Hall Problem Simulation</title>
      <link>https://forum.processing.org/two/discussion/13121/monty-hall-problem-simulation</link>
      <pubDate>Mon, 19 Oct 2015 17:33:36 +0000</pubDate>
      <dc:creator>ryansheets15</dc:creator>
      <guid isPermaLink="false">13121@/two/discussions</guid>
      <description><![CDATA[<p>Ok so I am working on a simulation of choosing to switch when confronted by the <a rel="nofollow" href="http://www.montyhallproblem.com/">Monty Hall Problem</a>. The problem is that it always comes out as 33% when it should be about 50%. What am I doing wrong?</p>

<pre><code>boolean[] door = new boolean[3];
int choice, next, switchthat, y, yes, no;
void setup() {
  size(500, 500);
  yes = 0;
  y = 0;
}

void draw() {
  background(0);
  pickDoor();
  rect(0, height-(yes*height/(yes+no)), width/2, (yes*height/(yes+no)));
  rect(width/2, height-(no*height/(yes+no)), width/2, no*height/(yes+no));
  text(yes*100/(yes+no), 100, 100);
}

void pickDoor() {
  door[0] = false;
  door[1] = false;
  door[2] = false;
  y = int(random(0, 3));
  door[y] = true;
  pickOne();
}

void pickOne() {
  choice = int(random(0, 3));
  pickNext();
}

void pickNext() {
  next = int(random(0, 3));
  if (next == choice) {
    pickNext();
  } else {
    switchit();
  }
}


void switchit() {
  switchthat = int(random(0, 3));
  if (switchthat == next) {
    switchit();
  } else if (switchthat == choice) {
    switchit();
  } else {
    check();
  }
}

void check() {
  if (door[switchthat]==true) {
    yes++;
  } else {
    no++;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>how to make a video: play + jump + play + jump …</title>
      <link>https://forum.processing.org/two/discussion/13095/how-to-make-a-video-play-jump-play-jump</link>
      <pubDate>Sun, 18 Oct 2015 17:46:20 +0000</pubDate>
      <dc:creator>ms68</dc:creator>
      <guid isPermaLink="false">13095@/two/discussions</guid>
      <description><![CDATA[<p>Hello,</p>

<p>I am also new to processing and would be very thankful if someone could help me with the following issue.</p>

<p>With the help of the video library I am trying to play a video that randomly jumps forwards, plays a limited and random amount of time and jumps randomly forward and plays again randomly until it reaches its end and repeats/loops.</p>

<p>Jumping is random inbetween the parameters of 15 and 30 seconds. Playing between 5 and 13 seconds.
I only got him jumping but not playing inbetween the jumps … althought the code I can give is without jumping so far:</p>

<pre><code>int clip_duration_max = 13;
int clip_duration_min = 5;
int clip_jump_max = 30;
int clip_jump_min = 15;

import processing.video.*;
Movie sequence;

void setup() {
  //size(displayWidth, displayHeight);
  size(640, 480);
  frameRate(25);
  sequence = new Movie(this, "sequence.mp4");
  sequence.loop();
}

void draw() {
  image(sequence, 0, 0);
  sequence.read(); 
  int sequence_duration = int(sequence.duration()); // get sequence duration
  int sequence_time = int(sequence.time());
  int jumper = int(random(clip_jump_min, clip_jump_max));  
  int sequence_length = int(random(clip_duration_min, clip_duration_max));
  int next_jumping_point = sequence_time + jumper + sequence_length;
}
</code></pre>

<p>Can anybody help me guiding to the next steps?</p>

<p>Thank you!</p>
]]></description>
   </item>
   <item>
      <title>How to change video speed with -if key pressed- ?</title>
      <link>https://forum.processing.org/two/discussion/13075/how-to-change-video-speed-with-if-key-pressed</link>
      <pubDate>Sat, 17 Oct 2015 21:59:58 +0000</pubDate>
      <dc:creator>buena_</dc:creator>
      <guid isPermaLink="false">13075@/two/discussions</guid>
      <description><![CDATA[<p>I'm trying to make my video change speed (random)  when I press a key... but I can't figure out how</p>
]]></description>
   </item>
   <item>
      <title>How to play an audio file sequentially.</title>
      <link>https://forum.processing.org/two/discussion/12966/how-to-play-an-audio-file-sequentially</link>
      <pubDate>Mon, 12 Oct 2015 16:35:21 +0000</pubDate>
      <dc:creator>JOSEPH</dc:creator>
      <guid isPermaLink="false">12966@/two/discussions</guid>
      <description><![CDATA[<p>Hey, I'm working on a new piece where a random number generator is connected to sound files of a lady I know screaming the numbers. So when the generator hits 1 it plays her screaming 1 and so on. I'm having trouble because I want the code to be in "void draw", however the audio files play over each other when I place it into that section.</p>

<p>I imagine that I need a piece of code to tell the next audio file to wait until the end of the last before it plays but I am an absolute beginner at coding, so I have no idea how to write it.</p>

<p>I have attached what I have done so far for reference, there is only one audio file in so far as I felt it was best to start simply and then add more audio files as I go.</p>

<pre lang="java">
        import ddf.minim.*;
    
        Minim house;
        AudioPlayer player1;
    
        int christine;
    
        void setup(){
          size(100,100);
        }
    
        void draw(){
      
           house = new Minim(this);
      
          player1 = house.loadFile("u.wav");
      
      
          christine = (int)random(10);
      
          println("christine is "  + christine);
        player1.play();
        player1.isPlaying();
        for (int =
        }
    </pre>
]]></description>
   </item>
   <item>
      <title>Is this possible??? (random numbers)</title>
      <link>https://forum.processing.org/two/discussion/12811/is-this-possible-random-numbers</link>
      <pubDate>Sun, 04 Oct 2015 03:52:44 +0000</pubDate>
      <dc:creator>TDog3337</dc:creator>
      <guid isPermaLink="false">12811@/two/discussions</guid>
      <description><![CDATA[<p>Is there a way to use increments using the random function??</p>

<p>For example, x = random(0,50) will give me a number between 0 and 50. What if I want it to give me either 0 or 50, but not the numbers in between??</p>
]]></description>
   </item>
   <item>
      <title>Processing float/int question</title>
      <link>https://forum.processing.org/two/discussion/12677/processing-float-int-question</link>
      <pubDate>Thu, 24 Sep 2015 22:01:51 +0000</pubDate>
      <dc:creator>benben</dc:creator>
      <guid isPermaLink="false">12677@/two/discussions</guid>
      <description><![CDATA[<p>Im trying to make a random number that is a non-decimal between (2,300) however It doesn't let me because float can't convert to int. Anyone know how to do this?</p>
]]></description>
   </item>
   </channel>
</rss>