我试图为每个要使用的线程生成随机数,但是所有线程都生成相同的数字。
每次运行程序时,数字都会更改,但是对于给定的运行,所有线程都会产生相同的数字。
如何为每个线程生成不同的随机数?
void *Customer(void *customer_id)
{
unsigned int iseed = (unsigned int)time(NULL);
srand (iseed);
int rastgele = rand() % 3 + 1;
int *id_ptr,customer_idd;
id_ptr=(int *) customer_id;
customer_idd=*id_ptr;
printf("This is thread : %d %d \n",customer_idd,rastgele);
pthread_exit(NULL);
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Altera DE2 FPGA板和verilog,设计了一个使用这些的简单CPU.我需要使用电路板的VGA输出打印寄存器的值.
我该怎么办呢?
我正在使用 JFormattedTextField,当我尝试删除字段中的值时,它会自动恢复以前的值。这种行为的原因是什么?我怎样才能阻止它恢复价值?
这是 JFormattedtextField 的代码。
jFormattedTextField2 = new javax.swing.JFormattedTextField(new DecimalFormat("###,###.##"));
Run Code Online (Sandbox Code Playgroud) 伙计们,
曾经是当你点击servlet/jsp时,app服务器会自动启动一个会话.它会将会话cookie放在第一个动态响应中,并在整个过程中进行跟踪.
我有一个休息后端,我注意到没有会话cookie被交易.所以我手动添加代码来发送JSESSIONID cookie:
@Context
private HttpServletRequest httpRequest;
// ...
@GET
@Path( "/{rcpGuid}" )
public Response myMethod( ... )
{
final HttpSession session = httpRequest.getSession();
final String sSessionId = session.getId();
...
return Response.status( Response.Status.SEE_OTHER ).
location( redirectUrl ).cookie( new NewCookie( "JSESSIONID", sSessionId ) );
}
Run Code Online (Sandbox Code Playgroud)
现在这导致返回2个JSESSIONID cookie副本,之前没有Set-Cookie标头.这就是我现在在浏览器的检查器中看到的内容:
Set-Cookie:JSESSIONID=sdm-Q1P6pRoQbKd4-9cJylGb; Path=/nn, JSESSIONID=sdm-Q1P6pRoQbKd4-9cJylGb; Version=1
Run Code Online (Sandbox Code Playgroud)
只要这样可行,我就不在乎.但不幸的是,当我的浏览器请求将URL重定向到(注意响应是"SEE_OTHER")时,该请求不具有会话ID.这导致我的应用程序无法正常运行.
任何见解?
在java中,所有方法都是按值传递的.但是今天我了解到构造函数是通过引用传递的.
// Attack the internals of a Period instance
Date start = new Date();
Date end = new Date();
Period p = new Period(start, end);
end.setYear(78); // Modifies internals of p!
Run Code Online (Sandbox Code Playgroud)
这有效,并且能够编辑私有字段.
这个决定的原因是什么?还是我错过了什么?
我试图改变动作栏中字幕的颜色,但它不会改变.
这是截图.

这是styles.xml
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:subtitleTextStyle">@style/MyActionBar.TitleTextStyle</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/actionbarBackground</item>
<item name="android:tabStripEnabled">true</item>
<item name="backgroundSplit">@color/white</item>
</style>
<style name="MyActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle">
<item name="android:textColor">@color/white</item>
</style>
Run Code Online (Sandbox Code Playgroud)