Skip to content

Commit ba8c9e6

Browse files
committed
Replaced the rand() function with arc4random() in all example apps.
1 parent fb2c70c commit ba8c9e6

21 files changed

Lines changed: 54 additions & 44 deletions

‎examples/CPTTestApp-iPad/Classes/CPTTestApp_iPadViewController.m‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ -(void)constructScatterPlot
216216
NSMutableArray *contentArray = [NSMutableArray arrayWithCapacity:100];
217217
for ( NSUInteger i = 0; i < 60; i++ ) {
218218
NSNumber *xVal = @(1 + i * 0.05);
219-
NSNumber *yVal = @(1.2 * rand() / (double)RAND_MAX + 1.2);
219+
NSNumber *yVal = @(1.2 * arc4random() / (double)UINT32_MAX + 1.2);
220220
[contentArray addObject:@{ @"x": xVal, @"y": yVal }];
221221
}
222222
self.dataForPlot = contentArray;

‎examples/CPTTestApp-iPhone-SpeedTest/Classes/CPTTestAppScatterPlotController.m‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ -(void)viewDidLoad
9595

9696
for ( NSUInteger i = 0; i < NUM_POINTS; i++ ) {
9797
xArray[i] = i;
98-
y1Array[i] = (NUM_POINTS / 3) * (rand() / (double)RAND_MAX);
99-
y2Array[i] = (NUM_POINTS / 3) * (rand() / (double)RAND_MAX) + NUM_POINTS / 3;
98+
y1Array[i] = (NUM_POINTS / 3) * (arc4random() / (double)UINT32_MAX);
99+
y2Array[i] = (NUM_POINTS / 3) * (arc4random() / (double)UINT32_MAX) + NUM_POINTS / 3;
100100
}
101101

102102
self.xxx = xData;
@@ -126,7 +126,8 @@ -(void)changePlotRange
126126
{
127127
// Setup plot space
128128
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;
129-
double ylen = NUM_POINTS * (rand() / (double)RAND_MAX);
129+
130+
double ylen = NUM_POINTS * (arc4random() / (double)UINT32_MAX);
130131

131132
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0) length:CPTDecimalFromDouble(NUM_POINTS)];
132133
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0) length:CPTDecimalFromDouble(ylen)];

‎examples/CPTTestApp-iPhone/Classes/CPTTestAppScatterPlotController.m‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ -(void)viewDidLoad
133133
NSMutableArray *contentArray = [NSMutableArray arrayWithCapacity:100];
134134
for ( NSUInteger i = 0; i < 60; i++ ) {
135135
NSNumber *xVal = @(1.0 + i * 0.05);
136-
NSNumber *yVal = @(1.2 * rand() / (double)RAND_MAX + 1.2);
136+
NSNumber *yVal = @(1.2 * arc4random() / (double)UINT32_MAX + 1.2);
137137
[contentArray addObject:@{ @"x": xVal,
138138
@"y": yVal }
139139
];
@@ -150,8 +150,8 @@ -(void)changePlotRange
150150
// Setup plot space
151151
CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;
152152

153-
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromDouble(3.0 + 2.0 * rand() / RAND_MAX)];
154-
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromDouble(3.0 + 2.0 * rand() / RAND_MAX)];
153+
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromDouble(3.0 + 2.0 * arc4random() / UINT32_MAX)];
154+
plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0.0) length:CPTDecimalFromDouble(3.0 + 2.0 * arc4random() / UINT32_MAX)];
155155
}
156156

157157
#pragma mark -

‎examples/CPTTestApp/Source/Controller.m‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ -(void)awakeFromNib
6565
-(id)newObject
6666
{
6767
NSNumber *x1 = @(1.0 + ( (NSMutableArray *)self.content ).count * 0.05);
68-
NSNumber *y1 = @(1.2 * rand() / (double)RAND_MAX + 1.2);
68+
NSNumber *y1 = @(1.2 * arc4random() / (double)UINT32_MAX + 1.2);
6969

7070
return @{
7171
@"x": x1,
@@ -288,7 +288,7 @@ -(void)setupScatterPlots
288288
NSMutableArray *contentArray = [NSMutableArray arrayWithCapacity:100];
289289
for ( NSUInteger i = 0; i < 60; i++ ) {
290290
NSNumber *x = @(1.0 + i * 0.05);
291-
NSNumber *y = @(1.2 * rand() / (double)RAND_MAX + 1.2);
291+
NSNumber *y = @(1.2 * arc4random() / (double)UINT32_MAX + 1.2);
292292
[contentArray addObject:@{ @"x": x,
293293
@"y": y }
294294
];

‎examples/CPTTestApp/Source/SelectionDemoController.m‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ -(void)initializeData
171171

172172
for ( NSUInteger i = 0; i < 100; i++ ) {
173173
NSNumber *x = @(i * 0.05);
174-
NSNumber *y = @(10.0 * rand() / (double)RAND_MAX - 5.0);
174+
NSNumber *y = @(10.0 * arc4random() / (double)UINT32_MAX - 5.0);
175175
[contentArray addObject:@{ @"x": x,
176176
@"y": y }
177177
];

‎examples/CorePlotGallery/src/plots/CandlestickPlot.m‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ -(void)generateData
4343
NSMutableArray *newData = [NSMutableArray array];
4444
for ( NSUInteger i = 0; i < 8; i++ ) {
4545
NSTimeInterval x = oneDay * i;
46-
double rOpen = 3.0 * rand() / (double)RAND_MAX + 1.0;
47-
double rClose = (rand() / (double)RAND_MAX - 0.5) * 0.125 + rOpen;
48-
double rHigh = MAX( rOpen, MAX(rClose, (rand() / (double)RAND_MAX - 0.5) * 0.5 + rOpen) );
49-
double rLow = MIN( rOpen, MIN(rClose, (rand() / (double)RAND_MAX - 0.5) * 0.5 + rOpen) );
46+
47+
double rOpen = 3.0 * arc4random() / (double)UINT32_MAX + 1.0;
48+
double rClose = (arc4random() / (double)UINT32_MAX - 0.5) * 0.125 + rOpen;
49+
double rHigh = MAX( rOpen, MAX(rClose, (arc4random() / (double)UINT32_MAX - 0.5) * 0.5 + rOpen) );
50+
double rLow = MIN( rOpen, MIN(rClose, (arc4random() / (double)UINT32_MAX - 0.5) * 0.5 + rOpen) );
5051

5152
[newData addObject:
5253
@{ @(CPTTradingRangePlotFieldX): @(x),

‎examples/CorePlotGallery/src/plots/ColoredBarChart.m‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ -(void)generateData
3030
if ( self.plotData == nil ) {
3131
NSMutableArray *contentArray = [NSMutableArray array];
3232
for ( NSUInteger i = 0; i < 8; i++ ) {
33-
[contentArray addObject:@(10.0 * rand() / (double)RAND_MAX + 5.0)];
33+
[contentArray addObject:@(10.0 * arc4random() / (double)UINT32_MAX + 5.0)];
3434
}
3535
self.plotData = contentArray;
3636
}

‎examples/CorePlotGallery/src/plots/CompositePlot.m‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ -(void)renderScatterPlotInLayer:(CPTGraphHostingView *)layerHostingView withThem
266266
NSMutableArray *contentArray = [NSMutableArray arrayWithCapacity:100];
267267
for ( NSUInteger i = 0; i < 60; i++ ) {
268268
NSNumber *xVal = @(1 + i * 0.05);
269-
NSNumber *yVal = @(1.2 * rand() / (double)RAND_MAX + 1.2);
269+
NSNumber *yVal = @(1.2 * arc4random() / (double)UINT32_MAX + 1.2);
270270
[contentArray addObject:@{ @"x": xVal, @"y": yVal }
271271
];
272272
}

‎examples/CorePlotGallery/src/plots/ControlChart.m‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ -(void)generateData
4444
double sum = 0.0;
4545

4646
for ( NSUInteger i = 0; i < numberOfPoints; i++ ) {
47-
double y = 12.0 * rand() / (double)RAND_MAX + 5.0;
47+
double y = 12.0 * arc4random() / (double)UINT32_MAX + 5.0;
4848
sum += y;
4949
[contentArray addObject:@(y)];
5050
}

‎examples/CorePlotGallery/src/plots/CurvedScatterPlot.m‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ -(void)generateData
6464

6565
for ( NSUInteger i = 0; i < 11; i++ ) {
6666
NSNumber *x = @(1.0 + i * 0.05);
67-
NSNumber *y = @(1.2 * rand() / (double)RAND_MAX + 0.5);
67+
NSNumber *y = @(1.2 * arc4random() / (double)UINT32_MAX + 0.5);
6868
[contentArray addObject:@{ @"x": x, @"y": y }
6969
];
7070
}

0 commit comments

Comments
 (0)