Skip to main content


This is the second version my only app in the Google Play Store that is somehow not down in the abbess. A recent comment made me realize that certain functionality in the previous version do not work on the newer Android devices. It was because the newer devices do not allow the main thread to do the background task (which is a great restriction. Kudos Android). In my case, the background task was to connect to to extract random numbers. So, I had to jettison the previous code and re-implement it using AsyncTask.


Code for DIY part

package com.randomayush;


import android.content.Context;

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class diy extends MainActivity {
    EditText min, max;
    Button submit;
    TextView box, status;
    String minimum, maximum;

    protected void onCreate(Bundle savedInstanceState) {

        min = (EditText) findViewById(;
        max = (EditText) findViewById(;
        submit = (Button) findViewById(;
        box = (TextView) findViewById(;
        status = (TextView) findViewById(;

        submit.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {

                InputMethodManager mgr = (InputMethodManager
                mgr.hideSoftInputFromWindow(min.getWindowToken(), 0);

                minimum = min.getText().toString() + "";
                maximum = max.getText().toString() + "";
                if (minimum == "" || maximum == "") {
                    status.setText("Result: Invalid Input. Missing Data...");
                } else if (Integer.parseInt(maximum) <= 
                                            Integer.parseInt(minimum)) {
                      ("Result: Invalid Input. Check Max/Min Values ..");
                } else {
                    new MyTask().execute();


    private class MyTask extends AsyncTask<String, String, String> {
        String statusMsg = "";

        protected String doInBackground(String... params) {
            statusMsg = "Status: Checking connection...";
            if (haveNetworkConnection()) {
                statusMsg = "Status: network available... connecting now...";
                try {
                    statusMsg = "Status: Connecting to";
                    return dome(minimum, maximum);
                } catch (Exception e) {
                    statusMsg = "Status: Connection failed...";
                    return ("");
            statusMsg = "Status: Connection failed...";
            return "";


        protected void onPostExecute(String result) {

            if (result.equals("")) {
                status.setText("DIY Random-Type: Pseudo");
                box.setText("" + (Integer.parseInt(minimum) + 
                (int) (Math.random() * (Integer.parseInt(maximum) - 
                 Integer.parseInt(minimum)) + .5)));

            else {
                status.setText("DIY Random-Type: Real");


        protected void onPreExecute() {

        protected void onProgressUpdate(String... text) {


    public boolean haveNetworkConnection() {
        ConnectivityManager cm = (ConnectivityManager
        return cm.getActiveNetworkInfo() != null && 

    public String dome(String min, String max) throws Exception {
        String sendto = "" + 
         min + "&max=" + max + "&col=1&base=10&format=plain&rnd=new";
        URL url = new URL(sendto);
        BufferedReader in = new BufferedReader
         (new InputStreamReader(url.openStream()));
        return (in.readLine());

Popular posts from this blog



The Zorganian Republic has some very strange customs. Couples only wish to have female children as only females can inherit the family's wealth, so if they have a male child they keep having more children until they have a girl. If they have a girl, they stop having children. What is the ratio of girls to boys in Zorgania?
The ratio of girls to boys in Zorgania is 1:1. This might be a little counter-intuitive at first. Here are some ways of tackling this problem. 1. Monte Carlo Simulation: Although, Monte Carlo simulation does not necessarily show why the result is 1:1, it is appropriate because of the very counter-intuitive nature of the problem. At the very least, it helps us see that the result is indeed 1:1. Therefore, this is a good start.
The following R code estimates the probability of a child being a boy in Zorgania. 
couples <-100000 boycount <-0for (i in1:couples){ # 0: boywhile (sample(c(0,1),1) ==0) { boycount=boycount+1 } } probability <- boycount/(co…

Simple Launcher

A simple minimal launcher application for Android devices that shows battery percentage using lzyzsd's CirclProgress library (ArchProgress used in this case) and BroadcastReciever for battery state, Android's clock widgets, a built-in flash light switch and an app list view that can be toggled. Currently, the toggle simply filters all the app that I am working on at present. Future implementation can allow users to select their favorite apps or populate second toggle based on the most used applications.