Skip to content
View in the app

A better way to browse. Learn more.

LCPDFR.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Random numbers not random

Featured Replies

I'm having some issues with some of my random numbers always being the same. I did some digging and realized that it's an issue in C# when you have too many NEW randoms close together because they use the same seed.

I have currently been using this:

int cophelps = new Random.Next(1, 3);

int suspectAttacks = new Random.Next(1,9);

however I am assuming I need to switch to:

int cophelps =  myRand.Next(1, 3);

int suspectAttacks = MyRand.Next(1, 9);

 

with private Random myRand; up top with the peds/vehicles etc at first time declaration. Is that correct?

Edited by download500

  • Author
22 minutes ago, tanu1215 said:

You could just sleep the fiber for like.. 5ms in between.

Question about that as well. When I have slept the fiber it seems to pause the whole system until sleep is complete.

Can I have unlimited sleeps (that wont affect other processes, if I use 

 

            GameFiber.StartNew(delegate
                {
                    GameFiber.Sleep(5000);

?

 

If so, can I make it GameFiber.StarNew(Delegate each time, or do I have to call it something different every time?

Edited by download500

1 hour ago, download500 said:

Question about that as well. When I have slept the fiber it seems to pause the whole system until sleep is complete.

Can I have unlimited sleeps (that wont affect other processes, if I use 

 


            GameFiber.StartNew(delegate
                {
                    GameFiber.Sleep(5000);

?

Well, if you're only using GameFiber.Sleep() to separate the seeds, then it shouldn't really be a problem as you're only sleeping for 500 milliseconds, which is half a second. You could sleep even less than that, because I think seeds go down to the millisecond (correct me if I am wrong).

But yes, start a new fiber for when you want to sleep.

It will keep from other things not being processed.

 

Edited by tanu1215

1 hour ago, download500 said:

however I am assuming I need to switch to:


int cophelps =  myRand.Next(1, 3);

int suspectAttacks = MyRand.Next(1, 9);

 

with private Random myRand; up top with the peds/vehicles etc at first time declaration. Is that correct?

Yep, this is the way to go.

33 minutes ago, download500 said:

Question about that as well. When I have slept the fiber it seems to pause the whole system until sleep is complete.

Can I have unlimited sleeps (that wont affect other processes, if I use 

 


            GameFiber.StartNew(delegate
                {
                    GameFiber.Sleep(5000);

?

 

If so, can I make it GameFiber.StarNew(Delegate each time, or do I have to call it something different every time?

Yeah, if you're wanting to sleep you should start a fresh GameFiber. The 'delegate' is the method used for starting the gamefiber, not its actual name, though you can name a GameFiber like so:

 

GameFiber.StartNew(delegate
	{
		GameFiber.Sleep(5000);
		Game.LogTrivial("I'm a sleepy fiber");
	}, "Sleepy Fiber Name");

 

 

 

Although I haven't quite figured out if this is actually useful in any way (though it does appear to at least show the name of the active fiber in logs, which can be good for troubleshooting)

Edited by Darkmyre
code formatting

My YouTube Channel: Darkmyre Gaming (Australian LSPDFR patrols, plugins in development, and other games)

My Discord Server | AusGamer Network

 

Please do not PM me for technical support or bug reports, use the appropriate forum or plugin's comments instead.

  • Management Team

You could also use a static random instance with a semi-random seed (system tick count for example). This way calling the function again in short period of time will get you different results because you don't initialize a new instance every call.

Please do not PM me unless really necessary (knowing you helps). If you think you need my attention in a topic, tag me.

4 hours ago, LMS said:

You could also use a static random instance with a semi-random seed (system tick count for example). This way calling the function again in short period of time will get you different results because you don't initialize a new instance every call.

What he said. If you create new instances of Math.Random within a short period of time, you are going to get the same results.

Instead, create one global static instance of Random, and use it everywhere in your plugin.

Stealth22
LSPDFR Tester | Plugin Developer
My Plugins: Code 3 Callouts | Traffic Control | Keep Calm | ALPR+

Please do not PM me for any kind of technical support.
I unfortunately do not have enough free time to answer every PM that I get. For issues with my plugins, please post in the comments section of the file, or it's forum thread. You'll get a much quicker response from me there than if you send me a PM; I do my best to respond to every question in the comments sections. For API/programming questions, please post them in the API Development forum, so all developers can benefit from the answer as well. Thanks!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Similar Content

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.