Jekyll2016-10-08T07:41:26+00:00https://topskychen.github.io/Qian's SiteGenerate Points in a Circle with Uniform Distribution2016-07-12T00:00:00+00:002016-07-12T00:00:00+00:00https://topskychen.github.io/articles/UniformPointGenerator<p>One naive but wrong idea is to randomly pick the degree and then the radius. We can find out the probability for a point located at <script type="math/tex">(\alpha, r)</script> in a circle is <script type="math/tex">p(\alpha, r) = \frac{1} {2\pi R}</script>, where R is the circle radius, which is different from the uniform probability <script type="math/tex">\frac{1} {\pi R^2}</script>.</p> <p>Instead, we can regard a circle composed of infinite triangles. Since we can easily generate uniform-distributed points in a triangle, it is easy to find the correct solution for a circle. See this <a href="http://stackoverflow.com/questions/5837572/generate-a-random-point-within-a-circle-uniformly">answer</a> for ref.</p> <p>As a conclusion, the pseudocode of generator is listed as follows:</p> <div class="language-python highlighter-rouge"><pre class="highlight"><code><span class="c"># assume the circle is centered at (0, 0) with radius 1</span> <span class="kn">from</span> <span class="nn">math</span> <span class="kn">import</span> <span class="n">pi</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">cos</span> <span class="kn">from</span> <span class="nn">random</span> <span class="kn">import</span> <span class="n">random</span> <span class="k">def</span> <span class="nf">generator</span><span class="p">():</span> <span class="n">d</span> <span class="o">=</span> <span class="mi">2</span><span class="o">*</span><span class="n">pi</span><span class="o">*</span><span class="n">random</span><span class="p">()</span> <span class="n">r</span> <span class="o">=</span> <span class="n">random</span><span class="p">()</span><span class="o">+</span><span class="n">random</span><span class="p">()</span> <span class="k">if</span> <span class="n">r</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span> <span class="n">r</span> <span class="o">=</span> <span class="mi">2</span><span class="o">-</span><span class="n">r</span> <span class="k">return</span> <span class="p">(</span><span class="n">r</span><span class="o">*</span><span class="n">cos</span><span class="p">(</span><span class="n">d</span><span class="p">),</span> <span class="n">r</span><span class="o">*</span><span class="n">sin</span><span class="p">(</span><span class="n">d</span><span class="p">))</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">):</span> <span class="k">print</span> <span class="n">generator</span><span class="p">()</span> </code></pre> </div>Generate Points in a Circle with Uniform Distribution.SSH Tunnel via JSCH Library2015-04-24T00:00:00+00:002015-04-24T00:00:00+00:00https://topskychen.github.io/articles/jsch-SSHTunnel<p>To retrieve resources behind the firewall, one solution is to connect to a public server first as a middle man, and then via the server to reach the resources. The solution is to establish a ssh tunnel.</p> <p>One can use a command line like <code class="highlighter-rouge">ssh -L xxx</code> (google to see details). However we use a jsch library to (build a <a href="https://github.com/topskychen/SSH_Tunnel">java program</a> and then) create a simple bash file.</p> <p>I have prepared a ssh.jar. To use it, type <code class="highlighter-rouge">java -jar ssh.jar local_port:ssh_server remote_server:remote_port</code>.</p> <p>By the way, we can use <code class="highlighter-rouge">lsof -i tcp:'port_no'</code> to see the the port information, e.g., <code class="highlighter-rouge">lsof -i tcp:9001</code>.</p>Establish a ssh tunnel to retrieve the resources behind the firewall.Hello World2015-04-08T00:00:00+00:002015-04-08T00:00:00+00:00https://topskychen.github.io/blog/so-simple-theme-blog<p>This is the hello world for my blog. See <a href="http://mmistakes.github.io/so-simple-theme/theme-setup/#running-jekyll">details</a> for more information.</p> <p>The most common lines are <code class="highlighter-rouge">bundle exec jekyll build</code> and <code class="highlighter-rouge">bundle exec jekyll serve</code>.</p>This is the hello world for my blog. See details for more information.