Random Numbers Using Dashboard Widgets

I'm developing a widget and I've noticed that the javascript call Math.random() returns the same sequence of values every time I place the widget. This seems to only be a problem in the dashboard, because when I load the widget in safari (or any other browser) the returned values are truly random (or close enough for my purposes).
It seems as if the javascript random number generator is seeded with the same value (probably 0) for the dashboard, but seeded with relatively unique number (current time) everywhere else.
So my question is ... is there any way around this? How would you recommend I get unique sequences of numbers? Should I write my own random number generator? Should I make calls to /dev/random? Is there any other way? Thanks.

I'm developing a widget and I've noticed that the javascript call Math.random() returns the same sequence of values every time I place the widget. This seems to only be a problem in the dashboard, because when I load the widget in safari (or any other browser) the returned values are truly random (or close enough for my purposes).
It seems as if the javascript random number generator is seeded with the same value (probably 0) for the dashboard, but seeded with relatively unique number (current time) everywhere else.
So my question is ... is there any way around this? How would you recommend I get unique sequences of numbers? Should I write my own random number generator? Should I make calls to /dev/random? Is there any other way? Thanks.

Similar Messages

  • Create Random Numbers using OLE Randomize and RND

    Hi,
    I've managed to create an excel spreadsheet by creating an object of type EXCEL.APPLICATION. I've also managed to rename the worksheet tabs, move from one tab to another as well as fill certain cells with numbers.
    I would now like to create a range of random numbers within one of these worksheets. I believe I should be using the Randomize and RND methods contained within the VBA OLE object. This is what I've done so far :
    DATA: gs_vba TYPE ole2_object,           "VBA object
               gs_math TYPE ole2_object.
    CREATE OBJECT gs_vba 'VBA'.
    CALL METHOD OF gs_vba 'MATH' = gs_math.
    CALL METHOD OF gs_math 'Randomize' = gs_math.
    CALL METHOD OF gs_math 'Rnd' = gs_math
      EXPORTING
        #1 = 1000.
    Is the above the right way to do it? If not, I would really appreciate your help, and if possible, some sample code to do this as well.
    Thanks and regards,
    Adeline.

    Hi,
    I've managed to create an excel spreadsheet by creating an object of type EXCEL.APPLICATION. I've also managed to rename the worksheet tabs, move from one tab to another as well as fill certain cells with numbers.
    I would now like to create a range of random numbers within one of these worksheets. I believe I should be using the Randomize and RND methods contained within the VBA OLE object. This is what I've done so far :
    DATA: gs_vba TYPE ole2_object,           "VBA object
               gs_math TYPE ole2_object.
    CREATE OBJECT gs_vba 'VBA'.
    CALL METHOD OF gs_vba 'MATH' = gs_math.
    CALL METHOD OF gs_math 'Randomize' = gs_math.
    CALL METHOD OF gs_math 'Rnd' = gs_math
      EXPORTING
        #1 = 1000.
    Is the above the right way to do it? If not, I would really appreciate your help, and if possible, some sample code to do this as well.
    Thanks and regards,
    Adeline.

  • CPU use Dashboard Widgets

    I would like to know if the dashboard widgets use CPU when you don't show the dashboard.
    Obviously, they use (a lot) of CPU when dashboard is activated, but what is going on when you're working with your Mac and dashboard is not activated?
    Thks for feedback!

    The widgets are all started the first time (after a boot) you open the Dashboard. The widgets will use memory from now on an CPU cycles. If you close the Dashboard, good written widgets will still use RAM, but NOT the CPU. However, there are/were some badly written ones that continued to use CPU cycles!
    You can see and find out easily if a widget is misbehaving by opening Activity Monitor. Place its window somewhere where no widget is covering it and open Dashboard. You'll see your widgets' CPU cycles go up. Close Dashboard and all of them should go back to 0.0% CPU.
    This way I removed some bad widgets or contacted the author for a better version.
    Björn

  • How to generate random numbers in a range using random class?

    I know how to use Math.random for this, but how would I generate random numbers using the random class?
    Say I want a number between 40 and 50, inclusive--how would I do this?
    What i have in mind is:
    int randomNumber = random.nextInt(max) + min;
    where max is 50 and min is 40. Is this correct?

    Fredddir_Java wrote:
    I know how to use Math.random for this, but how would I generate random numbers using the random class?
    Say I want a number between 40 and 50, inclusive--how would I do this?
    What i have in mind is:
    int randomNumber = random.nextInt(max) + min;
    where max is 50 and min is 40. Is this correct?What happened when you generated a couple hundred numbers that way? Did you get all the ints in the range you wanted?

  • Dashboard Widgets don't load

    I use dashboard widgets on my wireless router at home but they don't want to load now. I am hooked up to a landline connection and the widgets show up but aren't populating the data. Any ideas?

    i forgot to add... in console im getting this error when i drag icons off of the
    com.apple.launchd[80] ([0x0-0x7a07a].com.apple.dock[881]) Exited abnormally: Bus error

  • Generate multiple random numbers?

    Hi,
    I'm trying to generate random numbers using Math.random()* n;
    but I want the random numbers to reset to something different after
    a particular event is called. Instead, I've noticed the numbers
    either buzz away randomly in every frame (when placed inside
    onEnterFrame), or it picks random numbers once, and then uses those
    same values over and over (when placed outside the onEnterFrame).
    How do i get actionscript to generate new random numbers
    after each myMC.onPress = function(), or alternatively, after a
    score changes (like some kind of watch feature?)

    ok, i've got a half working version;
    function ranbot(x) {
    return Math.ceil(Math.random()* x) + "/" +
    Math.ceil(Math.random()* x);
    trace(ranbot(60));
    but is it possible to set up the function so the numerator is
    equal to or less than the denominator? Also, if the numerator is
    set to never exceed the denominator, then a large percentage -
    something like 25-50% of the output fractions would equal "1", like
    55/55, 23/23, 7/7, 28/28, and so on.
    I did something like this when using variables;
    var randombot2:Number = Math.ceil(Math.random()* 99);
    var randomtop2:Number = Math.min(randombot2 -
    Math.floor(Math.random()* randombot2* 0.5),
    Math.ceil(Math.random()* 99));
    - but I do not understand how this works in function
    terminology.

  • I need help with this program ( Calculating Pi using random numbers)

    hi
    please understand that I am not trying to ask anymore to do this hw for me. I am new to java and working on the assignment. below is the specification of this program:
    Calculate PI using Random Numbers
    In geometry the ratio of the circumference of a circle to its diameter is known as �. The value of � can be estimated from an infinite series of the form:
    � / 4 = 1 - (1/3) + (1/5) - (1/7) + (1/9) - (1/11) + ...
    There is another novel approach to calculate �. Imagine that you have a dart board that is 2 units square. It inscribes a circle of unit radius. The center of the circle coincides with the center of the square. Now imagine that you throw darts at that dart board randomly. Then the ratio of the number of darts that fall within the circle to the total number of darts thrown is the same as the ratio of the area of the circle to the area of the square dart board. The area of a circle with unit radius is just � square unit. The area of the dart board is 4 square units. The ratio of the area of the circle to the area of the square is � / 4.
    To simuluate the throwing of darts we will use a random number generator. The Math class has a random() method that can be used. This method returns random numbers between 0.0 (inclusive) to 1.0 (exclusive). There is an even better random number generator that is provided the Random class. We will first create a Random object called randomGen. This random number generator needs a seed to get started. We will read the time from the System clock and use that as our seed.
    Random randomGen = new Random ( System.currentTimeMillis() );
    Imagine that the square dart board has a coordinate system attached to it. The upper right corner has coordinates ( 1.0, 1.0) and the lower left corner has coordinates ( -1.0, -1.0 ). It has sides that are 2 units long and its center (as well as the center of the inscribed circle) is at the origin.
    A random point inside the dart board can be specified by its x and y coordinates. These values are generated using the random number generator. There is a method nextDouble() that will return a double between 0.0 (inclusive) and 1.0 (exclusive). But we need random numbers between -1.0 and +1.0. The way we achieve that is:
    double xPos = (randomGen.nextDouble()) * 2 - 1.0;
    double yPos = (randomGen.nextDouble()) * 2 - 1.0;
    To determine if a point is inside the circle its distance from the center of the circle must be less than the radius of the circle. The distance of a point with coordinates ( xPos, yPos ) from the center is Math.sqrt ( xPos * xPos + yPos * yPos ). The radius of the circle is 1 unit.
    The class that you will be writing will be called CalculatePI. It will have the following structure:
    import java.util.*;
    public class CalculatePI
    public static boolean isInside ( double xPos, double yPos )
    public static double computePI ( int numThrows )
    public static void main ( String[] args )
    In your method main() you want to experiment and see if the accuracy of PI increases with the number of throws on the dartboard. You will compare your result with the value given by Math.PI. The quantity Difference in the output is your calculated value of PI minus Math.PI. Use the following number of throws to run your experiment - 100, 1000, 10,000, and 100,000. You will call the method computePI() with these numbers as input parameters. Your output will be of the following form:
    Computation of PI using Random Numbers
    Number of throws = 100, Computed PI = ..., Difference = ...
    Number of throws = 1000, Computed PI = ..., Difference = ...
    Number of throws = 10000, Computed PI = ..., Difference = ...
    Number of throws = 100000, Computed PI = ..., Difference = ...
    * Difference = Computed PI - Math.PI
    In the method computePI() you will simulate the throw of a dart by generating random numbers for the x and y coordinates. You will call the method isInside() to determine if the point is inside the circle or not. This you will do as many times as specified by the number of throws. You will keep a count of the number of times a dart landed inside the circle. That figure divided by the total number of throws is the ratio � / 4. The method computePI() will return the computed value of PI.
    and below is what i have so far:
    import java.util.*;
    public class CalculatePI
      public static boolean isInside ( double xPos, double yPos )
         double distance = Math.sqrt( xPos * xPos + yPos * yPos );        
      public static double computePI ( int numThrows )
        Random randomGen = new Random ( System.currentTimeMillis() );
        double xPos = (randomGen.nextDouble()) * 2 - 1.0;
        double yPos = (randomGen.nextDouble()) * 2 - 1.0;
        int hits = 0;
        int darts = 0;
        int i = 0;
        int areaSquare = 4 ;
        while (i <= numThrows)
            if (distance< 1)
                hits = hits + 1;
            if (distance <= areaSquare)
                darts = darts + 1;
            double PI = 4 * ( hits / darts );       
            i = i+1;
      public static void main ( String[] args )
        Scanner sc = new Scanner (System.in);
        System.out.print ("Enter number of throws:");
        int numThrows = sc.nextInt();
        double Difference = PI - Math.PI;
        System.out.println ("Number of throws = " + numThrows + ", Computed PI = " + PI + ", Difference = " + difference );       
    }when I tried to compile it says "cannot find variable 'distance' " in the while loop. but i thought i already declare that variable in the above method. Please give me some ideas to solve this problem and please check my program to see if there is any other mistakes.
    Thanks a lot.

    You've declared a local variable, distance, in the method isInside(). The scope of this variable is limited to the method in which it is declared. There is no declaration for distance in computePI() and that is why the compiler gives you an error.
    I won't check your entire program but I did notice that isInside() is declared to be a boolean method but doesn't return anything, let alone a boolean value. In fact, it doesn't even compute a boolean value.

  • How do I save preferences/values using javascript in dashboard widget?

    How do I save preferences/values using javascript in dashboard widget? I apologize if this is a stupid question but I simply cant seem to find a way. For example, if on teh back side of the widget teh user chooses the color of the widget, where or how do I save that value so it is retained the next time the user goes to the dashboard. Also, once saved, how do I read the value?
    Thanks a mil....

    Please look into
    /Developer/Examples/Dashboard/Goodbye World/3-Saving Preferences directory for a comple example.
    Otherwise, wait until the following book is published :-))
    http://www.apress.com/book/bookDisplay.html?bID=10173
    Mihalis.

  • Hi, I have an iPhone 4 which rings people when it is locked, whether or not in my pocket.  I always lock it when not using it.  Can anyone help? It is calling random numbers, not the last person or anyone even recently called on my recents list. Thanks

    Hi, I have an iPhone 4 which rings people when it is locked, whether or not in my pocket.  I always lock it when not using it.  Can anyone help? It is calling random numbers, not the last person or anyone even recently called on my recents list. Thanks

    Pay no attention to iinami, the amount of replies to people saying their handsets must have been jailbroken everytime iTunes throws out an error is tremendous. (Clearly you don't need to have any real knowledge to get to level 3 on these forums, let's hope apple's geniuses know a lot more than some of their customers.)
    http://support.apple.com/kb/TS3694
    Solution below.
    Error 9
    This error occurs when the device unexpectedly loses its USB connection with iTunes. This can occur if the device is manually disconnected during the restore process. This issue can be resolved by performing USB troubleshooting, using a different USB dock-connector cable, trying another USB port, restoring on another computer, or by eliminating conflicts from third-party security software.

  • Using .docx-to-.html dashboard widget converter

    I've downloaded docx-converter.wdgt from the apple site in order to be able to read .docx files created by windows office 2007 and sent to me as attachments. The widget has installed fine on the dashboard. However, it seems that to use the widget, I need to drag the file onto the widget icon in the dashboard, and the dashboard fades when I click on the desktop to grab & drag the file icon. I've tried dragging the icon directly onto the dashboard icon with no luck.
    Thanks in advance for any advice.

    I've got the same problem. I found the PF12 method in the "how-to" on the converter's web page. However, when I push PF12 on my Mac, the "eject" symbol appeared, not the dashboard. Dashboard preferences are set to PF12 being dashboard. No helper keys helped. So, I set the Dashboard preferences temporarily to use the middle mouse button for Dashboard and then was able to get the file to drag to the widget. The conversion didn't work, however. I think that the .docx file I was sent isn't any good. Thanks Microsoft.
    JanG

  • Random numbers without using java funtions

    i need a formula to generate 100 random numbers 1-20
    any suggestions?

    Doesn't need much explaining. Did you try it?
    http://www.google.com/search?q=RNG+algorithms&sourceid=mozilla-search&start=0&start=0&ie=utf-8&oe=utf-8

  • Dashboard (Widget) turning ON/OFF automatically...Please Help!!

    Everything was working fine yesterday...
    I don't know if these two events are related, but today when I turned ON my computer and tried logging online I saw that Comcast had turned OFF my Internet Connection because of a late payment. Moments latter, after I made the payment and got my internet re-connected again this started happening...
    I logged online and for a minute or so it was fine, then all of a sudden there was a weird brief moment were I did not have any control over my computer... I thought something was being installed without my consent. So I tried logging OFF but the computer was Frozen, So I Shut down the computer manually using the ON/OFF button on my Display.... I don't remember exactly all the details of what else I did, but a few minutes latter I turned my computer back ON...
    My (Widget) dashboard window and the Volume Indicator started turning ON/OFF automatically. And now it's happening every few minutes and I can't control it.
    If I'm on my Desktop screen the Finder Window pops open prompting me: "you can not use the name that begins with Dot." The Keyboard keys Freeze and I have to randomly hit a bunch of keys or shut the computer down to use it again. As I was typing this email it would interrupt it and add one of these numbers (.0 or 3) to were ever the cursor was currently at. The mouse seams to work OK, but sometimes it freezes too.
    And, If I'm online the browser would freeze whenever the Widget application automatically started turning ON/OFF on the screen.
    Here are things I tried that I thought would fix it:
    1. I trashed the widget preferences from my User/Library.
    2. I trashed the widgets I thought were causing the problem.
    3. After the above did not work, I trashed the Dashboard Widget Application thinking it would be Deleted out of my computer. Unfortunately that did not fix the problem... I found out that the Widget dashboard Application is still somewhere in the sub layer of the system.
    I don't know what is going on and need some help here...
    So, can anyone Please help me out.. any Step by Step instructions would be greatly appreciated.
    -Frank
    Power Mac G5 Mac OS X (10.4.9)
    Power Mac G5 Mac OS X (10.4.9)

    Hi Frank, Welcome to Apple Discussions.
    First thing I'd do is Run Repair Disk from your Tiger DVD or discs that shipped with your Mac.
    1. Insert the Mac OS X Install disc that came with your computer, then restart the computer while holding the C key.
    2. When your computer finishes starting up from the disc, choose Disk Utility from the Installer menu. (In Mac OS X 10.4 or later, you must select your language first.)
Important: Do not click Continue in the first screen of the Installer. If you do, you must restart from the disc again to access Disk Utility.
    3. Click the First Aid tab.
    4. Click the disclosure triangle to the left of the hard drive icon to display the names of your hard disk volumes and partitions.
    5. Select your Mac OS X volume.
    6. Click Repair.
    If you repair errors run it until no errors found.
    Next, I'd try to repair this with 10.4.9 PPC Combo Update.
    This is a fuller install, as opposed to an incremental "delta" update so it should overwrite any files that are damaged or missing. It does not matter if you have applied it before. It has worked well for many.
    Remember to Verify Disk before update and repair permissions after update from /Applications/Utilities/Disk Utility.
    Good luck, let us know.
    -mj
    [email protected]

  • Dashboard widgets unresponsive to trackpad

    Some of the dashboard widgets - calculator and convertors - have stopped responding to trackpad commands. If I click on the calculator I can use keyboard commands to work it, but can no longer click on the numbers on the calculator to enter them.
    Stickies work fine, and all of the widgets that don't require trackpad are working fine, except for the "manage widgets" widget. It is also unresponsive to trackpad so I can neither close it nor check or uncheck the widgets listed in it.
    A longtime Windows user, I tried deleting the widgets (which I can do for all but the "manage widgets" one), shutting down the computer and restarting it, which used to resolve a surprising number of windows snags, but it did nothing for the dashboard.
    I didn't realize how much I relied on that little calculator until it stopped working. Can anyone rescue me from having to do long division in my head?

    I don't know why the trackpad isn't working properly for widgets, but as a possible work-around there is a Calculator app in the /Applications folder. If that one works, you could keep an icon for it in the Dock.

  • Dashboard widgets keep moving around!

    I'm guessing it is related to this question: (still unanswered)
    http://discussions.apple.com/thread.jspa?threadID=2080780&tstart=0
    But for some reason, my dashboard widgets like to shift around on my screen. I even moved them all into a gird into the upper left and corner of my screen so that it no matter what size screen I am using they will always be there. (as apposed to putting a widget in the bottom corner of my 1920 x 1200 monitor, unhooking it and then going back to the 1280 x 800 screen and finding the widget off screen.)
    So is there any way to "LOCK" the positions or just stop the random shifting around?
    Thanks,
    Scott

    I just meant open the Dashboard icons you want to use and put them where you want them.
    Dave M.
    MacOSG Founder/Ambassador  An Apple User Group  iTunes: MacOSG Podcast
    Macsimum News Associate Editor  Creator of 'Mac611 - Mobile Mac Support'

  • My info for battery charging says "Not Charging" when it is charging as per dashboard widget.

    My info for battery charging says "Not Charging" when it is charging as per dashboard widget. Since change to lion all slowed down do I need more ram ( have 2 gig). Lost  some icons in web site icons and other random icons. So far SL better.

    Yeah, it was purchased in August 2008. I'm not really sure what a charge cycle is, but I do plug it in and unplug it a lot to a power source. Mainly because I keep my computer on most of the time (either on or on sleep). So between taking it to classes and stuff, I'll recharge in between and when it's really low, otherwise I run it off the battery most of the time.
    On a sidenote, I have went to that information thing about about the battery after letting it sit plug in for a few hours, and now it has this information:
    Battery Information:
    Model Information:
    Serial Number: DP-ASMB016-38ea-4762
    Manufacturer: DP
    Device name: ASMB016
    Pack Lot Code: 0002
    PCB Lot Code: 0000
    Firmware Version: 0110
    Hardware Revision: 0500
    Cell Revision: 0200
    Charge Information:
    Charge remaining (mAh): 61993
    Fully charged: No
    Charging: No
    Full charge capacity (mAh): 61993
    Health Information:
    Cycle count: 324
    Condition: Good
    Battery Installed: Yes
    Amperage (mA): -1208
    Voltage (mV): 12129
    System Power Settings:
    AC Power:
    System Sleep Timer (Minutes): 0
    Disk Sleep Timer (Minutes): 10
    Display Sleep Timer (Minutes): 60
    Automatic Restart On Power Loss: No
    Wake On AC Change: No
    Wake On Clamshell Open: Yes
    Wake On LAN: Yes
    Display Sleep Uses Dim: Yes
    Battery Power:
    System Sleep Timer (Minutes): 10
    Disk Sleep Timer (Minutes): 10
    Display Sleep Timer (Minutes): 2
    Wake On AC Change: No
    Wake On Clamshell Open: Yes
    Display Sleep Uses Dim: Yes
    Reduce Brightness: Yes
    Hardware Configuration:
    UPS Installed: No
    AC Charger Information:
    Connected: No
    Charging: No
    Message was edited by: Akalboy
    Oh, forgot to note. Now the time remaining is 10 hours, which is DEFINITELY wrong.

Maybe you are looking for