Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- JMP User Community
- :
- Discussions
- :
- Random Uniform() keeps giving me the same number

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Mar 24, 2019 6:16 AM
(7015 views)

My script is returning random values from Random Uniform(), until I write some results to a data table. When I write to the table Random Uniform() always returns the same value. See comments in script below. Would appreciate any help.

Many thanks,

John

```
names default to here(1);
clear log();
include("defineVectorClass.jsl");
dtChaos = open("chaos.jmp");
proportionToCorner = 0.5;
A = new object(Vector(column(dtChaos,"x")[1],column(dtChaos,"y")[1]));
B = new object(Vector(column(dtChaos,"x")[2],column(dtChaos,"y")[2]));
C = new object(Vector(column(dtChaos,"x")[3],column(dtChaos,"y")[3]));
triangle = {A,B,C};
dtChaos<<Graph Builder(
Size( 534, 454 ),
Show Control Panel( 0 ),
Show Legend( 0 ),
Variables( X( :X ), Y( :Y ) ),
Elements( Points( X, Y, Legend( 3 ) ) )
);
current = new object(Vector(column(dtChaos,"x")[4],column(dtChaos,"y")[4]));
wait(2);
for(i=1,i<1000,i++,
bill = Random Uniform( 0, 3 );//this is where I am generating random value
show(randomuniform());
show(bill);
corner = triangle[Ceiling( bill )];
show(corner);
cornerTemp = corner<<clone;
show(cornerTemp);
currentTemp = current<<clone;
show(currentTemp);
cornerTemp:sub(currentTemp);
show(cornerTemp);
cornerTemp:mult(proportionToCorner);
show(cornerTemp);
current:add(cornerTemp);
show(current);
newX = current:x;
newY = current:y;
column(dtChaos,"X")[1+4]=newX;//the values generated above are random
column(dtChaos,"Y")[1+4]=newY;//unless these two lines are uncommented, then I get the same value from random uniform()
wait(2);
);
```

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

(Thanks @EvanMcCorkle and @danschikore for puzzling this out before I got in this morning!)

It is a bug in JMP's marker drawing; the easiest way to get your JSL going is to remove the Label state and change it to a color.

The problem is with the code that is positioning the labels around the data points; it needs a repeatable sequence of random numbers to juggle colliding labels, but it isn't keeping the reset to itself...as you noticed.

Another approach that keeps the labels needs a workaround in your JSL:

```
r = Random Seed State(); // the following statements make the graph update...
newX = current:x;
newY = current:y;
column(dtChaos,"X")[1+4]=newX;
column(dtChaos,"Y")[1+4]=newY;
wait(2);
Random Seed State(r);
```

this captures and restores the random state before and after the markers are drawn. The combination of changing a value in the table and the wait triggers the graph to update.

Thanks for the test case; a proper fix is underway.

Craige

5 REPLIES 5

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Random Uniform() keeps giving me the same number

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

(Thanks @EvanMcCorkle and @danschikore for puzzling this out before I got in this morning!)

It is a bug in JMP's marker drawing; the easiest way to get your JSL going is to remove the Label state and change it to a color.

The problem is with the code that is positioning the labels around the data points; it needs a repeatable sequence of random numbers to juggle colliding labels, but it isn't keeping the reset to itself...as you noticed.

Another approach that keeps the labels needs a workaround in your JSL:

```
r = Random Seed State(); // the following statements make the graph update...
newX = current:x;
newY = current:y;
column(dtChaos,"X")[1+4]=newX;
column(dtChaos,"Y")[1+4]=newY;
wait(2);
Random Seed State(r);
```

this captures and restores the random state before and after the markers are drawn. The combination of changing a value in the table and the wait triggers the graph to update.

Thanks for the test case; a proper fix is underway.

Craige

Highlighted
##

Another work-around is to turn off the Hide Overlapping Labels preference in the Graphs preferences group. That appears to be the source of the inteference with the random stream.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Random Uniform() keeps giving me the same number

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Random Uniform() keeps giving me the same number

Thanks Xan

Highlighted
##

Thanks for the quick response. Labels were not important for the simulation so I just turned them off like you suggested and everything is working great.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Random Uniform() keeps giving me the same number

Article Labels

There are no labels assigned to this post.