lundi 2 juillet 2018

find a word in string that comes multiple times in java script?

i want to find a word in a string multiple times

For Example : var string = "my name is "xyz" and my school name is "xyz" and my area name is "xyz" "

i want to find the location of word "my " eg code tells me that word my comes in location 0 , 21 , 50 i also tried many other JS methods but no one can give the result




dimanche 1 juillet 2018

Randomizing Tumblr-post order

I'm looking for a way to randomize the order of my Tumblr-posts every time the page is loaded. I found some pieces of code on here, but can't seem to find out where to place them. I don't have any experience with coding, so I'm lost. :)

An example of something I found on here:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
        .putauniqueclassnamehere{
        }
    </style>
    <script src="jquery-1.11.2.min.js"></script>
    <script>
        $(document).ready(function (name) {
            return function () {
                var max = $(name).length;
                $.each($(name), function (p1, p2) {
                    var randPos = Math.floor(Math.random() * (max - 0 + 1) + 0);
                    $(p2).insertBefore($(name)[randPos]);
                })
                return ;
            }
        }(".putauniqueclassnamehere"))
    </script>
</head>
<body>
    <div class="mytest">Test 1</div>
    <div class="mytest">Test 2</div>
    <div class="mytest">Test 3</div>
    <div class="mytest">Test 4</div>
    <div class="mytest">Test 5</div>
</body>
</html>

This is the blog: https://zinootje.tumblr.com/

Any help is appreciated! Thankyou!




Python how to include a string with random integer [duplicate]

I want to make a random police unit generator and the code is like so:

import random
unitnumbers = ('unit' , random.randint(1,999))
print(unitnumbers)

However, rather than printing "unit 63" , it prints ('unit', 378)

How could I make it print only the unit and random number?




In multithreading, why the other threads are not working when I have paused one thread for execution

I have three threads in my programming.According to the threading concept all the threads run asynchronously. So every thread is executed by the processor randomly. If I have just paused the execution of one thread by using thread.sleep() then other thread should work . Right?? And when the sleep time for the thread is over then it should again continue with its execution. But in my case when I am pausing one thread by using t2.sleep(10000) then all other threads are also getting paused. But they should have worked normally while the t2 thread is in wait.Can anyone tell me why is it so?

    import java.util.*;
    class square extends Thread
    {
       public int x;
       public square(int x)
       {
          this.x = x;
       }
       public void run()
       {
          System.out.println("Square of the number is " + x*x);
       }
    }
    class cube extends Thread
    {
       public int x;
       public cube(int x)
       {
          this.x = x;
       }
       public void run()
       {
           System.out.println("Cube of the number is " + x*x*x);
       }
    }

    class randgen extends Thread
    {
        public void run()
        {
           int num=0;
           Random r = new Random();
           try
           {
              for(int i=0;i<5;i++)
              {
                 num = r.nextInt(100);
                 System.out.println("The number generated is " + num);
                 square t2 = new square(num);
                 t2.start();
                 t2.sleep(10000);
                 cube t3 = new cube(num);
                 t3.start();

              }
          }
        catch(InterruptedException e)
        {
            System.out.println(e.getMessage());
        }
      }
}
public class Main
{
    public static void main(String args[])
    {
        randgen obj = new randgen();
        obj.start();

    }
}

OUTPUT

The number generated is 50
Square of the number is 2500
(After 10s) Cube of the number is 125000
The number generated is 36
Square of the number is 1296
(After 10s)
The number generated is 75
Cube of the number is 46656
Square of the number is 5625
(After 10s)
The number generated is 92
Cube of the number is 421875
Square of the number is 8464
(After 10s)
The number generated is 0
Cube of the number is 778688
Square of the number is 0 (After 10s)
Cube of the number is 0

Why am I getting the output after 10s ,instead by the concept of thread that thread which I am pausing should only pause for 10s and other thread should work synchronously.




how to generate random numbers from 1 to 4 and 8 in swift

I'm making an iOS SpriteKit game right now for first time I'm developing any app and it's tough challenge for me because it's really a big project for first time. My game is a Dice game and I defined move as 4 number. So when ever I touch the screen Player moves 4 blocks, But now I want to add Dice to the Game and I need Numbers from 1 to 4 and 8. So it will be 1,2,3,4 and 8 Numbers in the Dice. I know in Swift we can get Random Numbers with "arc4random" but how do I get numbers 1 to 4 and also 8 can I do it with arc4random and if possible I need 4 and 8 numbers to come 20% more often. Any Help will be really Helpful. Thanks.




Random real numbers with uniform distribution in verilog

Is there a function to generate random real numbers in the range [0,1] with uniform distribution in verilog. I tried $random%2 but it generates only integer values {-1,0,1}. There is a function uniform() in VHDL, is there a similar function in verilog?




random scheduler in xv6

What code should I use for a random scheduler in xv6?

I want to be a random scheduler that randomly chooses a job and does it without the processor getting it to the end, and eventually it will randomly bring the processor to another process.